Using ActiveRecord to manipulate data
ActiveRecord offers a convenient way to access and manipulate data stored in a database. This class is linked to a database table and represents a row of the linked table. Its attributes are the fields of the table and its methods allow us to perform common actions on database, such as selecting, inserting, or updating SQL statements.
Many common databases are supported by ActiveRecord, such as:
MySQL
PostgreSQL
SQLite
Oracle
Microsoft SQL Server
Also, some NoSQL databases are supported, such as:
Redis
MongoDB
ActiveRecord reads the table structure every time it is instanced and makes available table columns as its properties. Every change to the table structure is immediately available in the ActiveRecord object.
Therefore, if a table contains the fields id
, floor
, and room_number
, and if $model
is an instance of yii\db\ActiveRecord
, in order to access these fields, it will be enough to type:
$id = $model->id; $floor = $model->floor; $room_number = $model...