yii\db\Command::setSql PHP Method

setSql() public method

The previous SQL execution (if any) will be cancelled, and [[params]] will be cleared as well.
public setSql ( string $sql )
$sql string the SQL statement to be set.
    public function setSql($sql)
    {
        if ($sql !== $this->_sql) {
            $this->cancel();
            $this->_sql = $this->db->quoteSql($sql);
            $this->_pendingParams = [];
            $this->params = [];
            $this->_refreshTableName = null;
        }
        return $this;
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Указание текста sql запроса
  * @param string $sql текст sql запроса или имя sql-файла.
  * @param array $params параметры для построения sql запроса
  *      (@example [':p1'=>'v1', ':p2' => ['value', 'PDO_SQL_TYPE'], ':p3' => ['value', 'bind'=>'text'], ':p4' => [['v1', 'v2', ...]]])
  * @return static
  */
 public function setSql($sql, array $params = [])
 {
     if (!empty($sql)) {
         $sql = (new Parser($sql, $params))->getSql();
     }
     return parent::setSql($sql);
 }
All Usage Examples Of yii\db\Command::setSql