0

現在のモデルにも現在のデータベース接続にも含まれていないテーブルから最後に挿入された ID を取得する必要があります。どうすれば入手できますか?

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 に答える