Yii Get Last Inserted Id


Yii Get Last Inserted Id: If you are working with Yii models(database tables) and performing insert operation. You can get the last inserted id as below.


Syntax for Yii Get Last Inserted Id

Below is example of get Last inserted id in Yii.

Yii Get Last Inserted Id Using Models

If You are using models you can get Last inserted id as –

if($model->save())
{
    $LastInsertedId = $model->id 
   // this will be the last inserted id
}

if You Are Using Yii Pdo


$lastInsertedId = Yii::app()->db->getLastInsertId();

Which will return the last inserted id in the Yii table.


Advertisements

Add Comment

📖 Read More