A very important distinction lies in the data type of the column values.
When you return data in Active Record instances, column values will be automatically typecast according to the actual column types; on the other hand when you return data in arrays, column values will be strings (since they are the result of PDO without any processing), regardless their actual column types.
Instead of writing raw SQL statements, you would access Active Record attributes and call Active Record methods to access and manipulate the data stored in database tables.
For example, assume The above code is equivalent to using the following raw SQL statement for My SQL, which is less intuitive, more error prone, and may even have compatibility problems if you are using a different kind of database: In this tutorial, we will mainly describe the usage of Active Record for relational databases.
if its value has been modified since it was loaded from DB or saved to DB most recently.
For example, Note: If you use yii\db\Active Record::save() to update a counter column, you may end up with inaccurate result, because it is likely the same counter is being saved by multiple requests which read and write the same counter value.
You can do so by calling the yii\db\Active Record::find By Sql() method: Do not call extra query building methods after calling find By Sql() as they will be ignored.
As aforementioned, the data brought back from the database are populated into Active Record instances, and each row of the query result corresponds to a single Active Record instance.
Active Record provides an object-oriented interface for accessing and manipulating data stored in databases.
An Active Record class is associated with a database table, an Active Record instance corresponds to a row of that table, and an of an Active Record instance represents the value of a particular column in that row.