473,608 Members | 2,443 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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:m ysql: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 7313

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

Similar topics

1
4269
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 can give me a value which was inserted by a different user.
6
12667
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 when users send a card, their data is entered into the db via something like: INSERT vars into ecard_tbl....
3
41657
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 of entryID: Resource id #7" after EVERY insert (it never changes). What am I doing wrong? Thanks very much!
1
4110
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 auto_increment value that i want to use is the one from the client table and it will insert in the CONTACTS table but it will not in the JOBSHEET and KNOWLEDGE table. last_insert_id() has not worked because i have auto increment fields in all the tables pliz...
1
9599
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
2962
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 imiedietely after i insert value into session1... is there any other way to do it? insert into 2 tables at the same time ...? if(!($sessid)){ session_register('sessid'); mysql_query("insert into session1 set sessid=null,
2
2960
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 as running a SELECT query and using the result. I am getting the correct id, it is just losing the leading zeros. I have doulbe checked the table in the database, and it does have the leading zeros. Thanks for any help. $result =...
2
4375
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 that the id is going to be inserted into is auto_increment. I don't know what the problem could be. here is the table code:
5
3083
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
8059
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8000
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8495
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8330
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6011
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5475
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3960
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4023
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2474
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.