0

我需要从不属于当前模型当前数据库连接的表中获取最后插入的 ID :现在我在表中(pdtlisting),但我想从表中获取最后插入的 id(deallisting)。我怎么才能得到它?

4

1 回答 1

1

尝试这个..

它适用于 mySql..

LAST_INSERT_ID()

或者

它的 PHP ..

mysql_insert_id()

All the last_insert_id functions (be they PHP wrappers or the native mySQL one) typically refer to the last ID created using the current database connection. The last login was probably not created during the same request you are showing the table in, so this method won't work for you.

Use a normal SELECT to find out the newest login instead - e.g. by using ORDER by creationtime DESC LIMIT 1.

或者 在 Yii 中,你可以像这样找到最后插入的 id ..

Yii::app()->db->getLastInsertID();

你也可以参考这个链接..

http://www.yiiframework.com/doc/api/1.0/CActiveRecord#primaryKey-detail

于 2012-06-05T05:26:28.597 回答