db\ActiveRecord findBySql()

findBySql() public static method

Creates an yii\db\ActiveQuery instance with a given SQL statement.

Note that because the SQL statement is already specified, calling additional query modification methods (such as where(), order()) on the created yii\db\ActiveQuery instance will have no effect. However, calling with(), asArray() or indexBy() is still fine.

Below is an example:

$customers = Customer::findBySql('SELECT * FROM customer')->all();
public static yii\db\ActiveQuery findBySql ( $sql, $params = [] )
$sql string

The SQL statement to be executed

$params array

Parameters to be bound to the SQL statement during execution.

return yii\db\ActiveQuery

The newly created yii\db\ActiveQuery instance

doc_Yii
2016-10-30 16:56:19
Comments
Leave a Comment

Please login to continue.