yii\db\Command::execute PHP Method

execute() public method

This method should only be used for executing non-query SQL statement, such as INSERT, DELETE, UPDATE SQLs. No result set will be returned.
public execute ( ) : integer
return integer number of rows affected by the execution.
    public function execute()
    {
        $sql = $this->getSql();
        $rawSql = $this->getRawSql();
        Yii::info($rawSql, __METHOD__);
        if ($sql == '') {
            return 0;
        }
        $this->prepare(false);
        $token = $rawSql;
        try {
            Yii::beginProfile($token, __METHOD__);
            $this->pdoStatement->execute();
            $n = $this->pdoStatement->rowCount();
            Yii::endProfile($token, __METHOD__);
            $this->refreshTableSchema();
            return $n;
        } catch (\Exception $e) {
            Yii::endProfile($token, __METHOD__);
            throw $this->db->getSchema()->convertException($e, $rawSql);
        }
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Extended functional: flushing request local cache.
  * @inheritdoc
  */
 public function execute()
 {
     static::$requestLocalCache->flush();
     return parent::execute();
 }