5 messages in com.mysql.lists.perlInserting and retrieving id
FromSent OnAttachments
Jan Eden29 Jun 2004 07:34 
William R. Mussatto29 Jun 2004 09:39 
mayuran29 Jun 2004 09:43 
Jan Eden29 Jun 2004 14:21 
Jochen Wiedmann29 Jun 2004 23:24 
Subject:Inserting and retrieving id
From:Jan Eden (lis@janeden.org)
Date:06/29/2004 07:34:30 AM
List:com.mysql.lists.perl

Hi,

I have a subroutine which updates and inserts edited/new rows into my database.

Afterwards, I want it to display the edited/new row. This is easy in case of an
edited row, since I have an id to refer to:

if ($id) { $dbh->do("UPDATE items $set_clause WHERE item_id = $id"); } else { $dbh->do("INSERT INTO items $set_clause"); }

print
$q->redirect("media.pl?mode=get_changed&id=$id&media_type=$media_type");

But how can I get the id (INT PRIMARY KEY AUTO_INCREMENT) immediately after
inserting new data? Is there a good way to return such a value upon insertion?

Thanks,

Jan