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.
However, most content described here are also applicable to Active Record for No SQL databases.
To get started, declare an Active Record class by extending yii\db\Active Record.
Because each Active Record class is associated with a database table, in this class you should override the table Name() method to specify which table the class is associated with.
In the following example, we declare an Active Record class named operator to create a query object, you call yii\db\Active Record::find() to return a new query object which is of class yii\db\Active Query.
Below are some examples showing how to use Active Query to query data: Besides using query building methods, you can also write raw SQLs to query data and populate the results into Active Record objects.
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.
You can access the column values by accessing the attributes of the Active Record instances, for example, Note: The Active Record attributes are named after the associated table columns in a case-sensitive manner.
Yii automatically defines an attribute in Active Record for every column of the associated table. , which uses underscores to separate words in attribute names if your table columns are named in this way.