Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: DBI and last_insert_id

by G@SP@R (Initiate)
on Jan 29, 2009 at 13:30 UTC ( [id://739898]=note: print w/replies, xml ) Need Help??


in reply to DBI and last_insert_id

Olá cog. ;)

I remember having problems with last_insert_id to.
Ultimately I was able to get way with something like this.

$sth->execute( $entries{'a'}, $entries{'b'}, $entries{'b'} );
my $last_insert_id =$dbh->{q{mysql_insertid}};

It seems though that you can also use something like this:

$dbh->do('INSERT INTO table_name ...');
my $id = $dbh->last_insert_id(undef, undef, qw(table_name your_table_id)) or die "no insert id?";


About the select, try running the select just after you've inserted or after you made the call to last_insert_id whilst inside the transaction to make sure last_insert_id is returning the right values.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://739898]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2024-04-25 11:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found