note 88145 rejected from function.mysql-insert-id by danbrown
| From: | danbrown@php.net | Date: | Mon, 12 Jan 2009 23:49:08 +0000 |
| Subject: | note 88145 rejected from function.mysql-insert-id by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-149114@lists.php.net to get a copy of this message | ||
Note Submitter: pinkythakkar at gmail dot com
----
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);
---------------------