Cake\Database\Query::sql PHP Метод

sql() публичный Метод

This function will compile this query to make it compatible with the SQL dialect that is used by the connection, This process might add, remove or alter any query part or internal expression to make it executable in the target platform. The resulting query may have placeholders that will be replaced with the actual values when the query is executed, hence it is most suitable to use with prepared statements.
public sql ( ValueBinder $generator = null ) : string
$generator ValueBinder A placeholder object that will hold associated values for expressions
Результат string
    public function sql(ValueBinder $generator = null)
    {
        if (!$generator) {
            $generator = $this->valueBinder();
            $generator->resetCount();
        }
        return $this->connection()->compileQuery($this, $generator);
    }

Usage Example

Пример #1
2
 /**
  * Prepares a sql statement to be executed
  *
  * @param string|\Cake\Database\Query $query The query to prepare.
  * @return \Cake\Database\StatementInterface
  */
 public function prepare($query)
 {
     $this->connect();
     $options = [PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL];
     $isObject = $query instanceof Query;
     if ($isObject && $query->bufferResults() === false) {
         $options = [];
     }
     $statement = $this->_connection->prepare($isObject ? $query->sql() : $query, $options);
     return new SqlserverStatement($statement, $this);
 }
All Usage Examples Of Cake\Database\Query::sql