yii\db\ActiveQuery::createCommand PHP Method

createCommand() public method

Creates a DB command that can be used to execute this query.
public createCommand ( Connection | null $db = null ) : Command
$db Connection | null the DB connection used to create the DB command. If `null`, the DB connection returned by [[modelClass]] will be used.
return Command the created DB command instance.
    public function createCommand($db = null)
    {
        /* @var $modelClass ActiveRecord */
        $modelClass = $this->modelClass;
        if ($db === null) {
            $db = $modelClass::getDb();
        }
        if ($this->sql === null) {
            list($sql, $params) = $db->getQueryBuilder()->build($this);
        } else {
            $sql = $this->sql;
            $params = $this->params;
        }
        return $db->createCommand($sql, $params);
    }

Usage Example

Ejemplo n.º 1
0
 public function createCommand($db = null)
 {
     if ($db === null) {
         $db = Yii::$app->getDb();
     }
     return parent::createCommand($db);
 }
All Usage Examples Of yii\db\ActiveQuery::createCommand