This article will introduce to you the method of PHP to obtain the ID value of the data just inserted. PHP provides the mysql_insert_id() function. We only need to add echo mysql_insert_id() after inserting the data.
Example
The code is as follows
代码如下 |
复制代码 |
//执行插入数据库的语句
//……
$getID=mysql_insert_id();//$getID即为最后一条记录的ID
?>
|
|
Copy code
|
//Execute the statement inserted into the database
代码如下 |
复制代码 |
msyql_query("select last_insert_id()");
|
//……
$getID=mysql_insert_id();//$getID is the ID of the last record
?>
|
The PHP function mysql_insert_id() returns the value of the field defined by AUTO_INCREMENT after the last INSERT query was executed.
There is another way
The code is as follows
|
Copy code
|
msyql_query("select last_insert_id()");
last_insert_id() is a function of mysql and is also effective on the current link
This usage solves the bigint type problem encountered in mysql_insert_id ()
http://www.bkjia.com/PHPjc/628794.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/628794.htmlTechArticleThis article will introduce you to the method of PHP getting the ID value of the data just inserted. PHP provides us with the mysql_insert_id() function Just add echo mysql_insert_id() after inserting data. Example...
|