PHP Класс Prado\Data\TDbCommand

TDbCommand represents an SQL statement to execute against a database. It is usually created by calling {@link TDbConnection::createCommand}. The SQL statement to be executed may be set via {@link setText Text}. To execute a non-query SQL (such as insert, delete, update), call {@link execute}. To execute an SQL statement that returns result data set (such as select), use {@link query} or its convenient versions {@link queryRow} and {@link queryScalar}. If an SQL statement returns results (such as a SELECT SQL), the results can be accessed via the returned {@link TDbDataReader}. TDbCommand supports SQL statment preparation and parameter binding. Call {@link bindParameter} to bind a PHP variable to a parameter in SQL. Call {@link bindValue} to bind a value to an SQL parameter. When binding a parameter, the SQL statement is automatically prepared. You may also call {@link prepare} to explicitly prepare an SQL statement.
С версии: 3.0
Автор: Qiang Xue ([email protected])
Наследование: extends Prado\TComponent
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
__construct ( TDbConnection $connection, $text ) Constructor.
__sleep ( ) Set the statement to null when serializing.
bindParameter ( $name, &$value, $dataType = null, $length = null ) Binds a parameter to the SQL statement to be executed.
bindValue ( $name, $value, $dataType = null ) Binds a value to a parameter.
cancel ( ) Cancels the execution of the SQL statement.
execute ( ) : integer Executes the SQL statement.
getConnection ( ) : TDbConnection
getDebugStatementText ( ) : String
getPdoStatement ( ) : PDOStatement
getText ( ) : string
prepare ( ) Prepares the SQL statement to be executed.
query ( ) : TDbDataReader Executes the SQL statement and returns query result.
queryColumn ( ) : array Executes the SQL statement and returns the first column of the result.
queryRow ( $fetchAssociative = true ) : array Executes the SQL statement and returns the first row of the result.
queryScalar ( ) : mixed Executes the SQL statement and returns the value of the first column in the first row of data.
setText ( $value ) Specifies the SQL statement to be executed.

Описание методов

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

Constructor.
public __construct ( TDbConnection $connection, $text )
$connection TDbConnection

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

Set the statement to null when serializing.
public __sleep ( )

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

Binds a parameter to the SQL statement to be executed.
См. также: http://www.php.net/manual/en/function.PDOStatement-bindParam.php
public bindParameter ( $name, &$value, $dataType = null, $length = null )

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

Binds a value to a parameter.
См. также: http://www.php.net/manual/en/function.PDOStatement-bindValue.php
public bindValue ( $name, $value, $dataType = null )

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

Cancels the execution of the SQL statement.
public cancel ( )

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

This method is meant only for executing non-query SQL statement. No result set will be returned.
public execute ( ) : integer
Результат integer number of rows affected by the execution.

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

public getConnection ( ) : TDbConnection
Результат TDbConnection the connection associated with this command

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

public getDebugStatementText ( ) : String
Результат String prepared SQL text for debugging purposes.

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

public getPdoStatement ( ) : PDOStatement
Результат PDOStatement the underlying PDOStatement for this command It could be null if the statement is not prepared yet.

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

public getText ( ) : string
Результат string the SQL statement to be executed

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

For complex SQL statement that is to be executed multiple times, this may improve performance. For SQL statement with binding parameters, this method is invoked automatically.
public prepare ( )

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

This method is for executing an SQL query that returns result set.
public query ( ) : TDbDataReader
Результат TDbDataReader the reader object for fetching the query result

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

This is a convenient method of {@link query} when only the first column of data is needed. Note, the column returned will contain the first element in each row of result.
С версии: 3.1.2
public queryColumn ( ) : array
Результат array the first column of the query result. Empty array if no result.

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

This is a convenient method of {@link query} when only the first row of data is needed.
public queryRow ( $fetchAssociative = true ) : array
Результат array the first row of the query result, false if no result.

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

This is a convenient method of {@link query} when only a single scalar value is needed (e.g. obtaining the count of the records).
public queryScalar ( ) : mixed
Результат mixed the value of the first column in the first row of the query result. False is returned if there is no value.

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

Any previous execution will be terminated or cancel.
public setText ( $value )