Zend: how to obtain the ID of the inserted data-php Tutorial

Source: Internet
Author: User
How does zend obtain the ID of the primary key that just inserted a piece of data? ------ Solution -------------------- $ lastid $ db-& gt; lastInsertId (); in this way, we can obtain the latest id value ------ solution ------------------ to explore how to obtain the primary key id value of the data just inserted? ------ Solution --------- zend obtains the ID of the inserted data
How do I obtain the primary key id value of the inserted data?

------ Solution --------------------
$ Lastid = $ db-> lastInsertId ();

In this way, you can obtain the latest id value.
------ Solution --------------------
Discussion
How do I obtain the primary key id value of the inserted data?

------ Solution --------------------
PHP code
/// Insert into round_table // (noble_title, first_name, favorite_color) // VALUES ("King", "Arthur", "blue "); //// create a $ db object and then... // Construct an insert array in the format of "column name" => "data" and insert a data row $ row = array ('noble _ title' => 'King ', 'First _ name' => 'Arthur ', 'Favorite _ color' => 'blue',); // Insert a data table $ table = 'round _ table '; // I insert data rows and return the number of rows $ rows_affected = $ db-> insert ($ table, $ row); $ last_insert_id = $ db-> lastInsertId ();

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.