yii\db\Query::createCommand PHP Method

createCommand() public method

Creates a DB command that can be used to execute this query.
public createCommand ( Connection $db = null ) : Command
$db Connection the database connection used to generate the SQL statement. If this parameter is not given, the `db` application component will be used.
return Command the created DB command instance.
    public function createCommand($db = null)
    {
        if ($db === null) {
            $db = Yii::$app->getDb();
        }
        list($sql, $params) = $db->getQueryBuilder()->build($this);
        return $db->createCommand($sql, $params);
    }

Usage Example

Beispiel #1
0
 /**
  * Perform the DB Query
  *
  * @return array
  */
 public function perform()
 {
     // Create the command
     $command = $this->query->createCommand();
     // Execute the command and return
     return $command->queryAll();
 }
All Usage Examples Of yii\db\Query::createCommand