How to Get Yii last inserted ID from database

php Programming Yii

Today, We want to share with you Get Yii last inserted ID.
In this post we will show you Yii get last insert id in controller, hear for Yii get last record id we will give you demo and example for implement.In this post, we will learn about how to get id from database in Yii with an example.

List of all Google Adsense, VueJS, AngularJS, PHP, Laravel Examples.

Yii last inserted ID – PHP Yii Framework

Get Yii last inserted ID: If We are working with PHP Based Yii MVC models(from database tables) and run The insert/add operation in Database. We can return the last Yii Functions used to inserted id as below.

Syntax for Yii Get Last Inserted Id

Yii Get Last Inserted Id

$insert_id = Yii::app()->db->getLastInsertID();

Yii get last insert id in Models

PHP Yii Get Last Inserted Id Using Models

    $LastInsertedId = $model->id 
   // this will be get the last inserted id in Yii

Get Yii last inserted ID using PDO

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


This will return the Yii functions last inserted id in the PHP Yii from Database table.

Read :


You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Yii Get Last Inserted Id.
I would like to have feedback on my blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Related FAQ

Here are some more FAQ related to this Article:

  1.   How to get difference between two dates in laravel?
  2.   PHP list files in directory by date descending
  3.   Nested Child Routes in Vuejs Navigate Menu
  4.   Laravel 6 Count from Join Example
  5.   PHP Laravel MySQL Joins Tutorial with Examples
  6.   Laravel 7 Create Custom Helper Function Tutorial Example
  7.   Angular 9/8 Decimal Pipe Percent Pipe and Currency Pipe Example
  8.   Conditional When Case Statement in Laravel 6 Eloquent
  9.   PHP Convert XML to JSON with Attributes
  10.   For Loop inside React JSX components

Leave a Reply

Your email address will not be published. Required fields are marked *