Tutorial by Examples

Yii2 provides efficient ways to retrieve data from the database.Consider an example of a simple employee table having fields emp_id, emp_name and emp_salary. In order to retrieve the employee names and their salaries, we use the query. select emp_name,emp_salary from employee To generate the abo...
Multiple conditions can be written using where() method as given below. // Creates a new \yii\db\Query() object $query = new \yii\db\Query(); $rows = $query->select(['emp_name','emp_salary']) ->from('employee') ->where(['emp_name' => 'Kiran', 'emp_salary' => 2500...
The orderBy() method specifies the ORDER BY fragment of a SQL query.For example consider our employee table having fields emp_id, emp_first_name, emp_last_name and emp_salary.Suppose we need to order the result by increasing order of employee salaries.We can do it in sql as given below. Select * fr...

Page 1 of 1