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
Afficher le fichier Open project: pradosoft/prado Class Usage Examples

Méthodes publiques

Méthode 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 méthode

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

__sleep() public méthode

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

bindParameter() public méthode

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 méthode

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 méthode

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

execute() public méthode

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

getConnection() public méthode

public getConnection ( ) : TDbConnection
Résultat TDbConnection the connection associated with this command

getDebugStatementText() public méthode

public getDebugStatementText ( ) : String
Résultat String prepared SQL text for debugging purposes.

getPdoStatement() public méthode

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

getText() public méthode

public getText ( ) : string
Résultat string the SQL statement to be executed

prepare() public méthode

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 méthode

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

queryColumn() public méthode

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
Résultat array the first column of the query result. Empty array if no result.

queryRow() public méthode

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

queryScalar() public méthode

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
Résultat 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 méthode

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