Home > Backend Development > PHP Tutorial > PHP gets the ID value of the data just inserted_PHP tutorial

PHP gets the ID value of the data just inserted_PHP tutorial

WBOY
Release: 2016-07-13 17:15:26
Original
1473 people have browsed it

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
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template