Query Builder

Query Builder

Built on top of Database Access Objects, query builder allows you to construct a SQL query in a programmatic and DBMS-agnostic way- Compared to writing raw SQL statements, using query builder will help you write more readable SQL-related code and generate more secure SQL statements-

Using query builder usually involves two steps:

  1. Build a yii\db\Query object to represent different parts (e.g. SELECT, FROM) of a SELECT SQL statement.
  2. Execute a query method (e.g. all()) of yii\db\Query to retrieve data from the database-

The following code shows a typical way of using query builder:

登录查看完整内容