c'est une variable de session (session mysql pas php hein...):
sudo] password for max:
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 5.0.51a-3ubuntu5.1 (Ubuntu)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> CREATE DATABASE IF NOT EXISTS test;
Query OK, 1 row affected (0.07 sec)
mysql> USE test
Database changed
mysql> CREATE TABLE insertion(id int UNSIGNED AUTO_INCREMENT, PRIMARY KEY(id));
Query OK, 0 rows affected (0.07 sec)
mysql> INSERT INTO insertion VALUES();
Query OK, 1 row affected (0.05 sec)
mysql> INSERT INTO insertion VALUES();
Query OK, 1 row affected (0.00 sec)
mysql> SELECT LAST_INSERT_ID()
-> ;
+------------------+
| LAST_INSERT_ID() |
+------------------+
| 2 |
+------------------+
1 row in set (0.00 sec)
ensuite, on fait sur une autre console :
max@max-laptop:~$ sudo mysql -p
[sudo] password for max:
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.0.51a-3ubuntu5.1 (Ubuntu)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> USE test
Database changed
mysql> INSERT INTO insertion VALUES();
Query OK, 1 row affected (0.00 sec)
mysql> SELECT LAST_INSERT_ID();
+------------------+
| LAST_INSERT_ID() |
+------------------+
| 3 |
+------------------+
1 row in set (0.00 sec)
mysql>
puis on retourne sur la premiere :
mysql> SELECT LAST_INSERT_ID();
+------------------+
| LAST_INSERT_ID() |
+------------------+
| 2 |
+------------------+
1 row in set (0.00 sec)