Zend FRAMWORK1 Insert Last ID

Source: Internet
Author: User
Tags zend

Zend_db_adaptor documentation explains

Some RDBMS Brands support auto-incrementing primary keys. A table defined this way generates a primary key value automatically during an INSERT of new row. The return value of the Insert () method isn't the last inserted ID, because the table might not have a auto-incremented Column. Instead, the return value is the number of rows affected (usually 1).

If your table is defined with a auto-incrementing primary key, you can call the Lastinsertid () method after the insert. This method returns the "last value" generated in the scope of the current database connection.

So ...

$id = $db->lastinsertid ();

Should work


Your question is very unclear. Nevertheless, I-I-I-least-a part of a problem you have are that you are confusing insert method from Zend_db_adap Ter_abstract (or Zend_db_adapter_pdo_mysql) with the one from Zend_db_table_abstract. Both These classes have methods this are called insert, but they, work differently.

Insert methods from Zend_db_adapter_abstract returns the ' number of affected rows ' while inserts from Zend_db_table_ab Stract returns "The primary key of the row inserted".

The link that you provided are using insert from Zend_db_table_abstract. However, it seems that you are using insert from ' zend_db_table_abstract. For this reason your are always getting 1 in return.

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.