PHP Gets the ID value of the data just inserted _php tutorial

Source: Internet
Author: User
This article to introduce PHP to get just inserted data id value method, PHP provides the mysql_insert_id () function We just add the data after inserting Echo mysql_insert_id ().

Example

The code is as follows Copy Code

Execute the statement that inserts the database
......
$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's another way.

The code is as follows Copy Code

Msyql_query ("Select last_insert_id ()");

LAST_INSERT_ID () is a MySQL function that is also valid for the current link
This usage resolves the bigint type problem encountered in mysql_insert_id ()

http://www.bkjia.com/PHPjc/628794.html www.bkjia.com true http://www.bkjia.com/PHPjc/628794.html techarticle this article to introduce PHP to get just inserted data id value method, PHP provides the mysql_insert_id () function We just add the data after inserting Echo mysql_insert_id (). Example ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.