zend framwork1 insert last id

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 a new row. The return value of the insert() method is not the last inserted ID, because the table might not have an auto-incremented column. Instead, the return value is the number of rows affected (usually 1).

If your table is defined with an 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 think that at least a part of a problem you have is that you are confusing insert method from Zend_Db_Adapter_Abstract (or Zend_Db_Adapter_Pdo_Mysql) with the one from Zend_Db_Table_Abstract. Both these classes have methods that are called insert, but they work differently.

insert methods from Zend_Db_Adapter_Abstract returns the "The number of affected rows", while insert from Zend_Db_Table_Abstract returns "The primary key of the row inserted".

The link that you provided is using insert from Zend_Db_Table_Abstract. However, it seems that you are using insert from `Zend_Db_Table_Abstract. For this reason you are always getting 1 in return.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值