Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1069645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:26:51+00:00 2026-05-16T20:26:51+00:00

database= mysql language=php I am coding program to work like this PC1 =computer1 step

  • 0

database= mysql language=php

I am coding program to work like this

PC1 =computer1

step

1.PC1 insert data ,new ID from Auto-increment.

2.PC1 select last ID

everything work fine but..

The problem when your code is used by many computers at the same mili-sec.
For example

  1. PC1insert data,Auto-increment new ID

2.PC2 insert data ,Auto-increment new ID

3.PC1 select last ID <——-Wrong

4PC2 select last ID

How to config database or modify php code to prevent this , thankyou.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T20:26:52+00:00Added an answer on May 16, 2026 at 8:26 pm

    You should use mysql_insert_id (or the equivalent call for the API you are using) to get the ID of the last inserted row.

    I imagine that now you are doing this:

    SELECT MAX(id) FROM yourtable
    

    This won’t work unless you use transactions. But using the function mysql_insert_id is the better way.


    In the documenation there is also a caution and some notes that you should read:

    Caution: mysql_insert_id() will convert the return type of the native MySQL C API function mysql_insert_id() to a type of long (named int in PHP). If your AUTO_INCREMENT column has a column type of BIGINT (64 bits) the conversion may result in an incorrect value. Instead, use the internal MySQL SQL function LAST_INSERT_ID() in an SQL query.

    Note: Because mysql_insert_id() acts on the last performed query, be sure to call mysql_insert_id() immediately after the query that generates the value.

    Note: The value of the MySQL SQL function LAST_INSERT_ID() always contains the most recently generated AUTO_INCREMENT value, and is not reset between queries.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 537k
  • Answers 537k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer string[] lines = File.ReadAllLines(...); //i hope that the file is… May 17, 2026 at 1:48 am
  • Editorial Team
    Editorial Team added an answer The language in the upcoming C++0x standard (section 5.3.5 [expr.delete])… May 17, 2026 at 1:48 am
  • Editorial Team
    Editorial Team added an answer Spy++ (with Visual Studio 6) does the job quite nicely.… May 17, 2026 at 1:48 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Language: OO PHP 5+ DB: MySQL I am trying to insert data from a
I have a mySQL database with a number of tables with many fields. Is
When i am using mysql_real_escape_string on my unescaped strings the data in the database
I am basically trying to retrieve some data from a MySql server, and display
Im runing mySQL in a server where i need to drop tons of databases
I use a very simple query with Like to find product by its name
I want to upload data through CSV files in my contact management application. The
Gday All, I have a baffling problem whilst trying to insert some chinese characters
I apologize if this question is a duplicate. I have read many other mysqli
I have characters like these on our web site: Fémnyomó That is a street

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.