How to know the last record id inserted

if I insert a row into a table in my database, how do i get the last inserted id ?

$model = new Model;

$model->save(false);

echo $model->primaryKey;

Thanks for your reply…

But, what if at the same time are inserted 2 records ??

Could it be that $model->primaryKey returns a wrong id … or this cant happen cuz the table is locked until return the last inserted id …

[edit]

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

the blocking of sequence that assigns the primary key is another subject, usually handled by the database (autoincrement in mysql)




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