How to use the update() method of Yii 2 to update the data in your database

Hi guys, in this tutorial I will speak again about Yii Framework. And in tutorial I will show you how to use the update() method of Yii 2 to update the data in your database.

With update() you can easily update your database. This method its very simple to use.

If you want to update your data in a table with update(), you just need to add this code in your action:

$name = Nameoftable::findOne("10");
$name->fieldname = "new information";
$name->filedname2 = "about information";
$name->update();

With this code you will update data in your table where ID is 10.

In addition, Yii Framework version 2 provides a method, called updateAll() that helps us to update all rows in a table.

I have created also a video tutorial where you can see how to update the data in your database with Yii 2.0.









Leave a Comment