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

  • Home
  • SEARCH
  • 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

Related Questions

I'm using ASP.NET C# with database MYSQL, I follow this step on creating a
I just can't understand why is my database (mysql) behaving like this! My console
I'm creating dynamic website with Php and Mysql. So i need insert bangla language
I have a webapp written in PHP using a MySQL database backend. This question
Would you rather use mySQL database to store language variables or php variables? Please
I am very new to the C# programming language. I code primarily in PHP/MySQL
I'm using PHP as my scripting language and mySQL as my database. Im wondering
I am working on PHP and database MySQL. I have two tables in SQL
For the downvote fairies.. I know that php is the wrong language for this...
I'm working on a java 2ME app that submit data to mysql database (am

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.