- mysql_query ("SELECT Max (ID) from T1", $link);
Copy CodeUsing this method gives the highest ID value, which is the last value, but when a multilink thread, this maximum ID is not necessarily the self-increment ID value of the inserted data, and therefore does not apply to multithreading. Second, use the function: msyql_insert_id (); When the system executes the INSERT, and then executes the SELECT, it may have been distributed to a different back-end server, if you use PHP programming, this time should be through mysql_insert_id () To get the latest inserted ID, each time the insert ends, the corresponding AutoIncrement value has been calculated to return to PHP, you do not have to issue a separate query, directly with mysql_insert_id (). When a statement is inserted, it automatically returns the last ID (MySQL self-increment). And this function is only useful for the current link, that is, it is multi-user-safe. It is recommended to use this function; Problem: When the ID is bigint, it does not work. Third, use the query
- Msyql_query ("Select last_insert_id ()");
Copy CodeLAST_INSERT_ID () is a MySQL function that also works with the current link this usage resolves the bigint problem encountered in mysql_insert_id () Summary: It is recommended to use method two, in special cases, you can consider method three. |