9 messages in com.mysql.lists.mysqlRe: last_inserted_id
FromSent OnAttachments
Monika Plawna12 Apr 2000 11:07 
Matt Levine12 Apr 2000 11:22 
Monika Plawna12 Apr 2000 11:47 
Robert Goff12 Apr 2000 12:07 
Sam Mefford12 Apr 2000 12:19 
Monika Plawna12 Apr 2000 12:35 
Monika Plawna12 Apr 2000 13:22 
Thimble Smith13 Apr 2000 02:20 
Monika Plawna13 Apr 2000 09:56 
Subject:Re: last_inserted_id
From:Monika Plawna (pla@nortelnetworks.com)
Date:04/12/2000 12:35:36 PM
List:com.mysql.lists.mysql

Robert,

I was starting to suspect that's what was happening, thank you for timely confirmation. The prepare, execute and fetch statements work great now.

I gave the $insertId = $dbh->{'mysql_insertid'} a shot, but it returned no value. It generated no error either. Although I managed to get it working using the other method, my curiousity is getting the better of me, I think. So if anyone has any ideas as to why it might not work, please share! Thanks again to Rob!

Monika

Robert Goff wrote:

- my $req_id = $dbh ->do ('select last_insert_id()'); - - right after I perform an insert. I check the tables manually and the - entries get inserted properly, but the above statement always returns 1.

You're getting the status of the operation, not the value of the statement. 'do' doesn't return a value, just a status. You'll have to go through the prepare, execute, fetch sequence if you want to use the select statement.

Or you could use the db handle attribute: The DBD::mysql driver supports the following attributes of database handles (read only):

$infoString = $dbh->{'info'}; $threadId = $dbh->{'thread_id'}; $insertId = $dbh->{'mysql_insertid'}

These correspond to mysql_info(), mysql_thread_id() and mysql_insertid(), respectively.