In fact, there is a difference between the two. LAST_INSERT_ID() can return the id of a bigint value. However, mysql_insert_id returns int. If your id is unsigned int, or bigint. So, maybe what is returned is wrong. Use LAST_INSERT_ID() instead.
Some friends also return 0. I don’t know why. In fact, LAST_INSERT_ID() returns the ID of AUTO_INCREMENT.
If AUTO_INCREMENT is not set in the table structure, it cannot be returned.
There are still some people who still return 0. Then you need to check whether the insert delay function is used. In this case, the immediate return id value will not be returned.
Many people like to use select max(id)... to replace this last_insert_id. In fact, select max(id) is not thread-safe. It is very likely that if other threads insert new data, you will not be able to find it. The last inserted ID. And last_insert_id corresponds to a mysql connect, that is, it corresponds to your current thread and will not be interfered by other threads. If some strange errors occur in your database, for example, the information of data A is supposed to be updated,
As a result, data B is updated, and sometimes it is correct and sometimes it is incorrect. It will be very uncomfortable when there are many people. correct. Just check to see if select max(id) is used
The above has introduced the MYSQL tip - LAST_INSERT_ID, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.