PHP Class 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.
Since: 3.0
Author: Qiang Xue ([email protected])
Inheritance: extends Prado\TComponent
Datei anzeigen Open project: pradosoft/prado Class Usage Examples

Public Methods

Method Description
__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.

Method Details

__construct() public method

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

__sleep() public method

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

bindParameter() public method

Binds a parameter to the SQL statement to be executed.
See also: http://www.php.net/manual/en/function.PDOStatement-bindParam.php
public bindParameter ( $name, &$value, $dataType = null, $length = null )

bindValue() public method

Binds a value to a parameter.
See also: http://www.php.net/manual/en/function.PDOStatement-bindValue.php
public bindValue ( $name, $value, $dataType = null )

cancel() public method

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

execute() public method

This method is meant only for executing non-query SQL statement. No result set will be returned.
public execute ( ) : integer
return integer number of rows affected by the execution.

getConnection() public method

public getConnection ( ) : TDbConnection
return TDbConnection the connection associated with this command

getDebugStatementText() public method

public getDebugStatementText ( ) : String
return String prepared SQL text for debugging purposes.

getPdoStatement() public method

public getPdoStatement ( ) : PDOStatement
return PDOStatement the underlying PDOStatement for this command It could be null if the statement is not prepared yet.

getText() public method

public getText ( ) : string
return string the SQL statement to be executed

prepare() public method

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() public method

This method is for executing an SQL query that returns result set.
public query ( ) : TDbDataReader
return TDbDataReader the reader object for fetching the query result

queryColumn() public method

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.
Since: 3.1.2
public queryColumn ( ) : array
return array the first column of the query result. Empty array if no result.

queryRow() public method

This is a convenient method of {@link query} when only the first row of data is needed.
public queryRow ( $fetchAssociative = true ) : array
return array the first row of the query result, false if no result.

queryScalar() public method

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
return mixed the value of the first column in the first row of the query result. False is returned if there is no value.

setText() public method

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