Garth Webb said:
> You might have better luck with this on the [EMAIL PROTECTED] list,
> re: why this doesn't work. This works for me though:
>
> $pk = $dbh->{mysql_insertid};
>
> On Mon, 2004-06-14 at 21:42, Daniel Kasak wrote:
>> Hi all.
>>
>> I'm writing an app in Perl / Gtk2, and I'm having trouble with DBI's
>> last_insert_id() function.
>> I have so far:
>>
>> > eval {
>> > $sth->execute (@bind_values) || die $dbh->errstr;
>> > };
>> >
>> > # If the above failed, there will be something in the special
>> > variable $@
>> > if ($@) {
>> >
>> > # Dialog explaining error...
>> > my $dialog = &msgbox(
>> > $prospects->get_widget("Prospects"),
>> "Error updating recordset!",
>> > "Database Server says:\n" .
>> $dbh->errstr, 1
>> > );
>> >
>> > $dialog->run;
>> > $dialog->destroy;
>> >
>> > warn "Error updating recordset:[EMAIL PROTECTED]" . $@
>> .
>> > "\n\n";
>> >
>> > return 0;
>> >
>> > }
>> >
>> >
>> > $pk = $dbh->last_insert_id();
>>
>> The statement executes successfully, and the data is inserted. However
>> the above line that fetches the last_insert_id value from MySQL
>> always returns undef. The table has an auto_increment column. What's
>> going on?
>>
>> Dan
($pk) = $dbh->selectrow_array('SELECT LAST_INSERT_ID()');
BTW this also works in java.
--
William R. Mussatto, Senior Systems Engineer
Ph. 909-920-9154 ext. 27
FAX. 909-608-7061
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]