RE: [PHP] last_insert_id function
| From: | Mark Lipscombe | Date: | Wed, 24 Jan 2001 20:28:29 +0000 |
| Subject: | RE: [PHP] last_insert_id function | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-36371@lists.php.net to get a copy of this message | ||
Someone jump in here and correct me if I'm wrong, but by the time you
get around to executing the second query, LAST_INSERT_ID() from MySQL
isn't necessarily going to be the desired value, because another record
may well have been inserted in that time?
On 24 Jan 2001 18:25:27 +0900, Maxim Maletsky wrote:
> for example:
>
> $SQL = "INSERT INTO users SET name='Maxim', surname='Maletsky'";
>
> now you have to insert into another table where you need to relate that user
> to the entry:
>
> $SQL2 = "INSERT INTO questions SET question='how did you sleep?',
> made_by=LAST_INSERT_ID()";
>
> LAST_INSERT_ID() will be here equal to the auto_incremented id of the first
> $SQL statement.
>
> Hope this helps,
> Maxim Maletsky
>
>
> -----Original Message-----
> From: Jacky@lilst [mailto:jacky@activelifestyle.com]
> Sent: Thursday, January 25, 2001 7:16 AM
> To: php-general@lists.php.net
> Subject: [PHP] last_insert_id function
>
>
> I got this quote right out of the php manual. My Id field happen to be type
> BIGINT as it said so I tried using LAST_INSERT_ID(); and turn out to be
> error said "unidentified function". Any clue?
> *******************************************
> mysql_insert_id() converts the return type of the native MySQL C API
> function mysql_insert_id() to a type of long. If your AUTO_INCREMENT column
> has a column type of BIGINT, the value returned by mysql_insert_id() will be
> incorrect. Instead, use the internal MySQL SQL function LAST_INSERT_ID().
> ********************************************
> Jack
> jacky@activelifestyle.com
> "There is nothing more rewarding than reaching the goal you set for
> yourself"
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>