note 22413 rejected from function.mysql-insert-id by jimw
| From: | jimw@php.net | Date: | Wed, 07 Aug 2002 23:45:51 +0000 |
| Subject: | note 22413 rejected from function.mysql-insert-id by jimw | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-34489@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?