Home » How to Get Yii last inserted ID from database

How to Get Yii last inserted ID from database

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.

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.

Read Also:  Transpose of a matrix in Java Program

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

if($model->save())
{
    $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();

yiiframework

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

Read Also:  vue Check box binding Example

Read :

Summary

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 Pakainfo.com 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. Read Also:  Top 10 Yii Interview Questions and Answers for fresher
  2. Read Also:  Laravel Soft Delete Unique validations
  3. Read Also:  Codeigniter Helpers Example
  4. Read Also:  Laravel 5.8 Datatables Tutorial With Example
  5. Read Also:  laravel soft delete relationship Eloquent ORM
  6. Read Also:  .htaccess file Not Working on server with PHP - Fix
  7. Read Also:  How to Open URL in New Window using jQuery?
  8. Read Also:  PHP Automatically Stretch Background Fit Image
  9. Read Also:  Laravel 5.8 Datatables Tutorial With Example
  10. Read Also:  vue Check box binding Example

Leave a Comment

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