note 88145 added to function.mysql-insert-id

From: Date: Mon, 12 Jan 2009 23:46:16 +0000
Subject: note 88145 added to function.mysql-insert-id
Groups: php.notes 
Request: Send a blank email to php-notes+get-149113@lists.php.net to get a copy of this message
I have a web-based application and I created the following test to ensure that I get the correct incremented value. I created 2 connections to the database, link, link1. $link = mysql_connect($dbserver, $dbuser, $dbpswd) $link1 = mysql_connect($dbserver, $dbuser, $dbpswd) I used these links to insert a record in the database. mysql_query("insert into requests (name) values ( 'aaa' )", $link) mysql_query("insert into requests (name) values ( 'bbb' )", $link1) ; After the inserts, I printing the value of mysql_insert_id($link) and mysql_insert_id($link1): echo mysql_insert_id($link); echo mysql_insert_id($link1); Unfortunately, the values returned by these statements are the same. Can anyone help to determine the correct value of the generated ids? Here is the snippet of my code: ---------------------------- $link = mysql_connect($dbserver, $dbuser, $dbpswd) or die(""); mysql_select_db($dbname, $link) or die(""); mysql_query("insert into requests (name) values ( 'aaa' )", $link) or die(""); $link1 = mysql_connect($dbserver, $dbuser, $dbpswd) or die(""); mysql_select_db($dbname, $link1 ) or die(""); mysql_query("insert into requests (name) values ( bbb' )", $link1) or die(""); echo "Last inserted record has id using link =" . mysql_insert_id($link); echo "Last inserted record has id using link1 =" . mysql_insert_id($link1); mysql_close($link); mysql_close($link1); --------------------- ---- Server IP: 208.69.120.35 Probable Submitter: 98.234.191.127 ---- Manual Page -- http://www.php.net/manual/en/function.mysql-insert-id.php Edit -- https://master.php.net/note/edit/88145 Del: integrated -- https://master.php.net/note/delete/88145/integrated Del: useless -- https://master.php.net/note/delete/88145/useless Del: bad code -- https://master.php.net/note/delete/88145/bad+code Del: spam -- https://master.php.net/note/delete/88145/spam Del: non-english -- https://master.php.net/note/delete/88145/non-english Del: in docs -- https://master.php.net/note/delete/88145/in+docs Del: other reasons-- https://master.php.net/note/delete/88145 Reject -- https://master.php.net/note/reject/88145 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#149113) next »