Yii 从不属于当前控制器的表中获取最后插入的id

Yii 从不属于当前控制器的表中获取最后插入的id,yii,Yii,我需要从不属于当前模型或当前数据库连接的表中获取最后插入的ID:现在我在表中(pdtlisting),但我想从表中获取最后插入的ID(deallisting)。我怎样才能得到它?试试这个 这是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 th

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

试试这个

这是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();
您也可以参考此链接