note 22413 added to function.mysql-insert-id
| From: | robert-ramsey at uiowa dot edu | Date: | Mon, 17 Jun 2002 16:35:27 +0000 |
| Subject: | note 22413 added to function.mysql-insert-id | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-31945@lists.php.net to get a copy of this message | ||
Passing the the mysql_connect return value to mysql_insert_id certainly works.
Does that ensure that there's no problem with two web pages and users inserting records almost
simultaneously and so getting the wrong id back?
Consider the following:
create table foo (stuff varchar(255), id int(16) auto_increment not null, primary key(id);
on the web page, you've got this:
$myconnection=mysql_connect($server, $user, $pass);
$query="insert into foo(stuff) values ($user_response);
$insert_result=mysql_db_query($db, $query, $myconnection);
$numb= mysql_insert_id($connection);
print "<h1>$numb</h1>\n";
Now if we have this sequence of events:
A inserts a record [id = 1]
B inserts a record [id = 2]
A calls mysql_insert_id
B calls mysql_insert_id
A prints $numb
B prints $numb
Ideally, because we passed the $myconnection to mysql_insert_id, A should see 1 and B should see 2.
Is this correct? If I didn't pass $myconnection to mysql_insert_id, would the result be that
both users would see 2?
--
http://www.php.net/manual/en/function.mysql-insert-id.php
http://master.php.net/manage/user-notes.php?action=edit+22413
http://master.php.net/manage/user-notes.php?action=delete+22413
http://master.php.net/manage/user-notes.php?action=reject+22413