Today, when I was in a database category, I was unable to obtain the ID of the last saved data. after repeated troubleshooting, I still did not find the cause, however, I summarized the IDs of the last record in the specified mysql table or the IDs of the latest inserted records. let's take a look at them. Development... today, when I was in a database category, I was unable to obtain the ID of the last saved data. after repeated troubleshooting, I still did not find the cause, however, I summarized the IDs of the last record in the specified mysql table or the IDs of the latest inserted records. let's take a look at them.
I like development best. Writing a program can improve your strength and add some code to your favorites! It is really good. For some reason, you need to obtain the maximum id of the database. So this section of php obtains the largest id code of the database. Here, max (id). here, the id is used to obtain the largest id. For other fields, enter other fields.
Method 1
$ Fh = mysql_query ("select MAX (id) from log"); $ c_echo = mysql_fetch_array ($ fh); echo $ c_echo;
Method 2
The PHP function mysql_insert_id () returns the value of the field defined by AUTO_INCREMENT after the last INSERT query is executed.
Method 3
Msyql_query ("select last_insert_id ()");
Last_insert_id () is a mysql function that also takes effect on the current link.
This method solves the bigint type problem in mysql_insert_id ().
Tutorial address:
Reprinted! But please include the article address ^