Working in phpMyAdmin for now:
order
table strucure:
OrderID int(11) auto_increment
CustomerID varchar(50)
BillAddr varchar(200
I had the same issue, solution was do the the query at the same time. In other words first query and the second(last_insert_id) query should be executed at the same time. Not as two different execution.
LAST_INSERT_ID()
returns the id of the last inserted row and is not bound to any table. So if you create a new row:
INSERT INTO table VALUES('a', 'b', 'c');
It will return the last id (whatever value the new primary key has).
SELECT LAST_INSERT_ID();
=> 123
For details, please take a look at the manual:
LAST_INSERT_ID() (with no argument) returns a BIGINT (64-bit) value representing the first automatically generated value that was set for an AUTO_INCREMENT column by the most recently executed INSERT statement to affect such a column. For example, after inserting a row that generates an AUTO_INCREMENT value, you can get the value like this:
If you just want to get last ID in a table, you can do it like this:
SELECT id FROM table ORDER BY id DESC LIMIT 1;
As stated in the manual:
LAST_INSERT_ID() (with no argument) returns a BIGINT (64-bit) value representing the first automatically generated value that was set for an
AUTO_INCREMENT
column by the most recently executed INSERT statement to affect such a column. For example, after inserting a row that generates anAUTO_INCREMENT
value, you can get the value like this:mysql> SELECT LAST_INSERT_ID(); -> 195
by indicating a table, you repeat the select statement for EVERY row in said table.
it does not affect the result of your query, other than to repeat the same value.
if running in phpmyadmin, you might want to check that Persistent Connections is set to TRUE, otherwise you will ALWAYS receive 0 as a result of LAST_INSERT_ID().
Do it like this:
INSERT INTO `one`(`id`, `name`) VALUES (NULL,'shivam');
select last_insert_id();
Perform no other query after insert and they both should execute together