• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 365
  • Last Modified:

mysql_insert_id() or LAST_INSERT_ID()

I need to do like > 
$sql=mysql_query("INSERT INTO blog (id, subject) VALUES (NULL,'mytext')");
just after this I need to insert another information in another table where I need to set same Unique ID of last query like :

$sql2=mysql_query("INSERT INTO blog2 (id, subject) VALUES (mysql_insert_id(),'second text')");

Though this all works fine but I am wondering what if 1000 users are visiting the site same time and inserting rows so could it be incorrect because of it . what after executing first line from a users PC and before second line  if some other user execute the  same the code ?
0
amitbravo
Asked:
amitbravo
  • 2
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
that code will work fine, as you use the same connection/session.
0
 
UmeshMySQL Principle Technical Support EngineerCommented:
Use LAST_INSERT_ID() instead of mysql_insert_id()

so your query should be

$sql2=mysql_query("INSERT INTO blog2 (id, subject) VALUES ( LAST_INSERT_ID(),'second text')");
0
 
UmeshMySQL Principle Technical Support EngineerCommented:
sorry I misread the question.. both works LAST_INSERT_ID() & mysql_insert_id().. and there would not be any problem no matter 1000 user or 1000K user ..

http://dev.mysql.com/doc/refman/5.0/en/getting-unique-id.html
0
 
amitbravoAuthor Commented:
then I am going to use mysql_insert_id() .
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now