last_insert_id() in perl/DBI

I

Irene Mettias

Hello,

I've just installed perl DBI v1.38 which according to the
documentation supports the method last_insert_id(). For some reason
the return value I get is undef.

Here is my source code :

#!/usr/local/bin/perl

use DBI;

$dbh = DBI->connect('DBI:mysql:FOOD', 'foodadmin', '');
$stmnt = "INSERT INTO RECIPES (name, description, source) VALUES
('test recipe', 'testing', 'imagination')";
$dbh->do($stmnt);
$code = $dbh->last_insert_id();
#$code = $dbh->last_insert_id(undef, undef, undef, undef);
## also tried the above line as in the documentation
if ($code == undef)
{
print "ERROR can't get code\n";
}

$dbh->disconnect();

The insert statement works fine but I can't get the code :

ERROR can't get code


The table defenition is :

mysql> desc RECIPES;
+-------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+----------------+
| code | int(11) | | PRI | NULL | auto_increment |
| name | varchar(80) | | | | |
| description | varchar(240) | YES | | NULL | |
| steps | text | YES | | NULL | |
| source | varchar(80) | YES | | NULL | |
+-------------+--------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)

So what am I doing wrong .. PLEASE HELP.

Thanks.

Irene
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top