P粉9738995672023-08-24 17:15:20
There is a function that can know what the last id inserted in the current connection is
mysql_query('INSERT INTO FOO(a) VALUES(\'b\')'); $id = mysql_insert_id();
Plus using max is a bad idea as it may cause problems if your code is used simultaneously in two different sessions. .
The function is called mysql_insert_id
P粉8951872662023-08-24 10:49:27
If you are using PDO, use PDO::lastInsertId
.
If you are using Mysqli, please use mysqli::$insert_id
.
If you are still using Mysql:
But if you must, use mysql_insert_id
.