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;


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 …



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