I am running MySQL 3.23.41-17 on a stock SuSE 7.3 install. I have a table
"customers" with an auto-incrementing primary key "customer_id". If I insert
a record:
mysql> insert into customers(customer_id) values ("10");
and then ask for the last insert:
mysql> select last_insert_id();
(which I thought was the correct syntax) I get the response "0".
If I ask:
mysql> select last_insert_id() from customers;
I get as many zeros as there are records.
If I ask:
mysql> select last_insert_id(customer_id) from customers;
I get the ids for all the records.
If I then ask:
mysql> select last_insert_id();
I get the last record inserted (which was what was supposed to happen, I
thought), BUT if I insert another record and repeat:
mysql> select last_insert_id();
I get the same number as the last time I asked - ie the last but one.
However, if I then ask:
mysql> select last_insert_id(customer_id) from customers;
followed by:
mysql> select last_insert_id();
I get the most recently-added record number.
Could some kind person on the list please explain what is happening here, and
why the standard syntax does not give the results I expect?
Thank you.
Kevin
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php