This problem has been encountered by the cliff before, too long did not write do not remember (seems to be the CI frame directly related functions), and then met again, rolled to check again, here is not the case is PDO, but with the outdated connection and implementation of how to operate after the way.
What SQL statement is implemented, but obviously inappropriate, when the number of people to operate, suddenly chaos.
So here, with the mysql_insert_id () function, he will return the auto_incresement value.
| The code is as follows |
Copy Code |
<?php $link = mysql_connect (' localhost ', ' mysql_user ', ' Mysql_password '); if (! $link) { Die (' Could not connect: '. Mysql_error ()); } mysql_select_db (' mydb '); mysql_query ("INSERT into mytable (product) VALUES (' Kossu ')"); printf ("Last inserted record has ID%d", mysql_insert_id ()); ?> |
At first I still think this function will not encounter the same problem, and then Nova told me is based on the current database connection, immediately not afraid of it.
Of course there are.
| The code is as follows |
Copy Code |
mysql_query ("SELECT Max (ID) from T1", $link); |
Now, of course, this connection is out of the way,
There are also instructions here:
Warning
This extension is deprecated as of PHP 5.5.0, and would be removed in the future. Instead, the mysqli or pdo_mysql extension should be used. Also mysql:choosing an API guide and related FAQs For more information. Alternatives to this function include:
mysqli_insert_id ()
Pdo::lastinsertid ()