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

Re: Getting null value from last_insert_id()

by ferreira (Chaplain)
on Apr 05, 2007 at 11:09 UTC ( [id://608447]=note: print w/replies, xml ) Need Help??


in reply to Getting null value from last_insert_id()

If that:
$tmp_query="insert into <TableName> values('','');"; $sth = $dbh->prepare($tmp_query); $sth->execute(); $sth->finish();
looks like your actual code, you have some problems to work out before getting something from last_insert_id().

First, DBI drivers don't expect ';' ending the statements most of the time (even though I don't know especifically about mysql). I would suggest to remove this terminator.

Second, if you are not using RaiseError => 1, every problem/error is passing unnoticed if you don't check the return of DBI methods like prepare, execute and finish. One of the easiest ways is to add RaiseError => 1 to your connection creation and let DBI throw an exception if something goes wrong.

After getting rid of these issues, you may try with more confidence to interpret the results of last_insert_id() (and it is possible it just works then and does not need more tweaks). Also consider Re: Getting null value from last_insert_id() and make sure you need last_insert_id after all.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-04-18 05:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found