How to insert data in database using Yii Framework 2.0

In this tutorial I will explain to you how you can easily insert data in database using Yii Framework 2.0. In Yii Framework 2.0 you can easily insert data in database using the function insert().

So, if you want to insert data in your database, you just need to create a new action in your controller or you can use an existing action.

You can insert data in your database by using this code:

$article = new Article; // the name of database
$article->id = $id;
$article->genre_id = $genreId;
$article->content = $content;
$article->insert();

$article->id, $article->genre_id and $article->content is the name of fields in the table.

With $article->insert(); you can insert data in your database.

So, as you can see its very simple to insert data in database by using Yii Framework 2.0.

I have created also a video tutorial where you can see how insert data in database.









Leave a Comment