Re: mysql_insert_id?
| From: | Jimmy | Date: | Wed, 16 Jan 2002 17:47:00 +0000 |
| Subject: | Re: mysql_insert_id? | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-80770@lists.php.net to get a copy of this message | ||
Hi DL,
>> the only problem i can think of might occur with pconnect is,
>> last_insert_id() will return you the last inserted ID from
>> previous 'session', not current 'session'.
>> to prevent this, you should call last_insert_id() only when
>> your INSERT query executed succesfully.
> =Of course a "right-living" boy like me, cannot conceive of why one would
> look up LAST_INSERT other than immediately after the INSERT/UPDATE command...
calling last_insert_id() after INSERT is the number one rule
of course :)
What i mean was, what if the INSERT query fail, but the script still
execute the last_insert_id() function?
Most probably the returned value would be wrong, because it will
return the last_insert_id of previous INSERT query (from previous
'session')
> =What I have noted is that the PHP manual
> (http://www.php.net/manual/en/function.mysql-insert-id.php) works
> slightly differently (and possibly more simply), as well as
> emphasising the "immediately after" relationship between this call
> and the preceding INSERT.
I might be wrong, but i think PHP's mysql_insert_id() must be using
MySQL's API function call.
Meaning, it will return whatever value MySQL return.
Or in other word, mysql_insert_id() and last_insert_id() will return
the same result.
I have look thru the manual link above, and i think the phrase
"immediately after" in the manual is more to advise the user to do
mysql_insert_id() immediately after the INSERT query,
because last_insert_id value might get overwritten by the newest one.
the "immediately after" phares in the manual doesn't mean that PHP's
mysql_insert_id() function is somehow tied to the previous/last
INSERT query, so that if the INSERT fails then mysql_insert_id()
will intelegently return the correct value.
just my 1 cent....
--
Jimmy
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The average woman would rather have beauty than brains, because the average man can see better than
he can think.