Tag Archives: Yii Select

Yii Framework 2 : Advanced Select Query

Scopes() Scopes Sample 1: class User extends \yii\db\ActiveRecord { namespace app\models; public static function olderThan($query, $age = 5) { $query->andWhere(‘userid > :age’, [‘:age’ => $age]); } } // call the scope function $model = User::find()->olderThan(5)->all(); Sample 2: class User extends \yii\db\ActiveRecord { // … public static function active($query) { $query->andWhere(‘status = 1’); } } // […]

Yii Framework 2 : Select Query For Model

This tutorial will help you to get the list of function to retrieve or select the data from the database using model of yii2.0 framework. I updated most of the functions it will helpful for yii2.0 select query method. find() select() all() one() where() orderBy() count() asArray() indexBy() limit() offset() Limit With Pagination() LIKE Condition […]

Yii Framework 2 : SQL Select Query

findBySql() queryAll() queryOne() queryColumn() queryScalar Query With Prepared Statements() Query Class Note //Before use the Query Class, We have to add the following namespace use yii\db\Query; $connection = \Yii::$app->db; findBySql Sample 1: $sql = ‘SELECT * FROM tbl_user’; $model = User::findBySql($sql)->all(); Sample 2: $sql = ‘SELECT * FROM tbl_user’; $model = User::findBySql($sql)->one(); queryAll $model = $connection->createCommand(‘SELECT […]