Home > php教程 > php手册 > php获取刚刚插入数据的ID值

php获取刚刚插入数据的ID值

WBOY
Release: 2016-05-25 16:48:08
Original
2170 people have browsed it

本文章来给大家介绍php获取刚刚插入数据的ID值方法,php提供了mysql_insert_id()函数我们只要在插入数据后面加入echo mysql_insert_id() 即可.

实例代码如下:

<?php
//执行插入数据库的语句 
//…… 
$getID=mysql_insert_id();//$getID即为最后一条记录的ID 
?>
Copy after login

PHP 函数 mysql_insert_id() 是返回在最后一次执行了 INSERT 查询后,由 AUTO_INCREMENT 定义的字段的值.

还有一种方法

实例代码如下:

msyql_query("select last_insert_id()");
Copy after login

last_insert_id()是mysql一个函数也是对当前链接起效,此用法解决了 mysql_insert_id () 中遇到的 bigint 型问题


永久链接:

转载随意!带上文章地址吧。

Related labels:
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template