473,569 Members | 2,422 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Returning the last autoinc value

Claus Mygind
571 Contributor
I'm trying to get the last auto increment value inserted into a table.

I am using MySQL v.5 with php v5.3. The table engine is MyISAM.

The manual states this is what should be done
Expand|Select|Wrap|Line Numbers
  1. SELECT LAST_INSERT_ID();
  2.  
What I get returned is this
"current_field" :null,
"field_count":n ull,
"lengths":n ull,
"num_rows":null ,
"type":null

The insert statement looks like this
Expand|Select|Wrap|Line Numbers
  1. insert into myTable set col1=val1, col2=val2
  2.  
I have also tried it with setting the key value to null, with no further luck

Then I created a test table with just two fields key and fill. I tested the code on the MySQL browser like this
Expand|Select|Wrap|Line Numbers
  1. insert into t values (null,'xyz');
  2.  
  3. select last_insert_id();
  4.  
and the value displayed on the console was 0 not the last id.

Any suggestions would be appreciated.
Dec 23 '13 #1
2 1567
Claus Mygind
571 Contributor
Well I finally got it to work.

Here is the php code

Expand|Select|Wrap|Line Numbers
  1. mysql_insert_id();
  2.  
Dec 23 '13 #2
Dormilich
8,658 Recognized Expert Moderator Expert
The manual states this is what should be done
Expand|Select|Wrap|Line Numbers
  1. SELECT LAST_INSERT_ID();
What I get returned is this
Expand|Select|Wrap|Line Numbers
  1. "current_field":null,
  2. "field_count":null,
  3. "lengths":null,
  4. "num_rows":null,
  5. "type":null
not really important any more, but the MySQL manual also states that LAST_INSERT_ID( ) returns a BIGINT and not an array/object. so I’d rather assume that the code you used for calling did not expect a single number to be given.
Dec 24 '13 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
8731
by: PT | last post by:
I got a problem. And thats..... First of all, I got these three tables. ------------------- ------------------ ---------------------- tblPerson tblPersonSoftware tblSoftware ------------------- ------------------ ---------------------- PID PName PID* SID* SID SWName --- ...
3
2135
by: Sree | last post by:
Hello All, When will it be benefical to return a value from a function as a const reference ? Say I have classes like this class B { public: int someValue1; int someValue2;
13
4496
by: Matthias Kaeppler | last post by:
Hi, I was wondering why library implementors often make getter functions return strings by value (copies). For example, in boost::filesystem the leaf() function returns an std::string by value. So does Gnome::Vfs::FileInfo::get_name(). Isn't that unnecessary overhead? I could as well return by reference to const-string and avoid
4
1286
by: manning_news | last post by:
I've got the following query in SQL 2000: select a.SSN, a.MonthName, a.IMClinicDay, b.IMClinicDay as SecondDay from tblResidentRotations a inner join view7 b on a.SSN = b.SSN where a.AcademicYear = '2004-2005' and a.SSN = '999999999' and datename(month, a.IMClinicDateFirst) = b.MonthName
18
1761
by: John Salerno | last post by:
Ok, I wrote this all by myself, which explains why it doesn't work. It is meant to take a number and generate the next number that follows according to the Morris sequence. It works for a single number, but what I'd like it to do is either: 1. repeat indefinitely and have the number of times controlled elsewhere in the program (e.g., use...
5
32002
by: Veeru71 | last post by:
Given a table with an identity column (GENERATED BY DEFAULT AS IDENTITY), is there any way to get the last generated value by DB2 for the identity column? I can't use identity_val_local() as the INSERTS are happening in a different session. Eg, We have the following table....
7
2363
by: dunkleypilot | last post by:
Hello, I have created a database to track the flights on three aircraft owned by the flight school I manage. The relevant fields in the FlightRecords table are Date, AircraftID, HourMeterOut, and HourMeterIn. - = TotalFlightTime. Each month I generate a report that calculates the total flight time for each aircraft. That report calls a...
3
4991
by: bogdan | last post by:
Hi, I have a stored procedure that returns a single value. Example: SELECT @RowCount = COUNT(*) FROM t WHERE RETURN @RowCount I created a data set, table adapter, and adapter's method configured for the stored proc and as returning a single value. The wizard created an adapter method that calls SqlCommand.ExecuteScalar(). The...
7
2489
by: Ryan Le Piane | last post by:
Hi everyone, I am trying to program a Form Pay Estimator and it calculates the gross pay, taxes owed, and net pay for an individual employee. For some reason my CalculateTaxes method in my Pay() class is not returning the correct value. This is the code I have here: In my Pay() class: class Pay { //declare variables ...
1
1575
by: ram1592 | last post by:
how to get grid last column value using c#
0
7703
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...
0
8132
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7678
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7982
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...
0
6286
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5222
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...
0
3644
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1226
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
944
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.