Re: mysql_insert_id?
| From: | DL Neil | Date: | Tue, 15 Jan 2002 22:59:41 +0000 |
| Subject: | Re: mysql_insert_id? | ||
| References: | 1 | Groups: | php.db php.general |
| Request: | Send a blank email to php-general+get-80640@lists.php.net to get a copy of this message | ||
Hi Wee,
> Is it possible that I would get the wrong ID (Not the ID I just inserted in
> Auto_Increment field) by using mysql_insert_id function if someone is also
> inserting record at the same time? How does mysql_insert_id work accurately?
=A couple of things here:
1 if the field is defined as "Auto_Increment" then YOU will not insert an ID. Leave the
field out of the INSERT
statement or transfer NULL, and MySQL will insert the correct ID value according to the
'increment' policy.
The construction of the mysql_insert_id() looks like this:
$AutoIncrementId = mysql_insert_id( $MySQLConnection );
Note that the function argument is the connection to MySQL (not the db/tbl !). Thus the ID is a
by-product of
the connection (and the most recent INSERT it handled) - re-read the appropriate page in the manual
for more
information, if required.
2 because the (function argument) controlling feature is the connection, it is not possible for
another
concurrent user to 'steal' your ID or influence the ID returned to you - it's all
yours!
The only way to get the "wrong" ID is to perform two IDs and then (vainly) try to get hold
of the previous ID -
only the latest ID is available.
Clear now?
=dn