Database access objects
Yii database access objects, commonly referred to as DAO, provide a powerful object-oriented API to work with a relational database. As the foundation for more complex database access, such as Query Builder and Active Record, DAO enables us to work directly with our database through SQL statements and PHP arrays. Consequently, it is significantly more performant to work with DAO statements than it is to work with either Active Record or Query Builder.
At the core of DAO is our yii\db\Connection
class, or more commonly, our db
component \Yii::$app->db
. Since our db
component is already properly configured for SQLite, we'll use it moving forward. With DAO, there are two general types of queries that we can run: queries that return data, such as SELECT
queries, and queries that execute data, such as DELETE
or UPDATE
.
Tip
If you use the yii\db\Connection
class directly, you'll need to explicitly call the open()
method before you can run any queries against that connection...