5 messages in com.mysql.lists.mysqlRe: how to get the id of a newly inse...
FromSent OnAttachments
ji...@work12 Jan 2000 17:34 
Paul DuBois12 Jan 2000 18:23 
Jamie Le Tual12 Jan 2000 20:59 
Nicolas Prade13 Jan 2000 02:46 
Paul DuBois13 Jan 2000 04:46 
Subject:Re: how to get the id of a newly inserted record???
From:Paul DuBois (pa@snake.net)
Date:01/12/2000 06:23:46 PM
List:com.mysql.lists.mysql

At 5:35 PM -0800 2000-01-12, jim@work wrote:

ok, i'm sure i have missed this in previous discussions, and it seems so elemetary (uh, ya) that i must have overlooked it in the manual (albeit, it's huge).

when i insert a record into the database from PERL (using DBI), that has an auto-increment primary key, how do i got about getting that primary key value??

In SQL:

SELECT LAST_INSERT_ID()

In DBI:

$dbh->{mysql_insert_id}

In PHP:

mysql_insert_id()

Of course, you can use the SQL statement in either DBI or PHP, too.