469,325 Members | 1,602 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,325 developers. It's quick & easy.

last_insert_id() in perl/DBI

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
Jul 19 '05 #1
0 6945

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Michal Adamczakk | last post: by
6 posts views Thread by jim | last post: by
3 posts views Thread by Vic Spainhower | last post: by
3 posts views Thread by jx2 | last post: by
2 posts views Thread by WebSnozz | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.