472,354 Members | 1,913 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,354 software developers and data experts.

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 7163

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Michal Adamczakk | last post by:
hi, how to implement mysql's last_insert_id() ? i know that seqences and oids are great. the one thing i miss is that they are not session specific. i mean selecting last_value from seqence...
6
by: jim | last post by:
Hi, I have a site with various parts which allow users to enter info via forms which gets entered into various tables in a MySQL db (I'm using ASP, rather than PHP). I have an ecards bit, and...
3
by: Vic Spainhower | last post by:
Hello, I am trying to get the value of the Auto-Incremented key that was assigned using LAST_INSERT_ID(). However, when I execute the following PHP statements after the insert I only get: "value...
1
by: simbarashe | last post by:
I am trying to insert an auto_increment value into multiple tables but its seems to lose its value after the the second insert statement and my code is as follows can any1 please help. The...
1
seshu
by: seshu | last post by:
thank sir now one more dubt how to use last_insert_id( ) because i want get all the last inserted and then update only those values can you say me how? regards seshu
3
by: jx2 | last post by:
hi guys i would appriciate your coments on this code - when i ran it for the very first time it doesnt see @last = LAST_INSERT_ID() but when i ran it next time it read it properly i need to know it...
2
by: WebSnozz | last post by:
I am losing the leading zeros when I get autoincrement IDs from a column with ZEROFILL enabled. I would like to have the leading zeros. I have tried both the php function last_insert_id as well...
2
by: wizardry | last post by:
Hello - I'm recently a newbie to mysql, but have experiance in oracle, mssql, access, etc... Here is my problem, i've created the table needed to test the audit procedures. the data element...
5
Markus
by: Markus | last post by:
The MySQL manual states: I wonder what is considered a 'client'. Is that simply just different connections to the database?
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made but the http to https rule only works for...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it so the python app could use a http request to get...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.