Class \Prado\Data\TDbCommand
TDbCommand represents an SQL statement to execute against a database. It is usually created by calling TDbConnection::createCommand. The SQL statement to be executed may be set via \Prado\Data\setText.
To execute a non-query SQL (such as insert, delete, update), call execute. To execute an SQL statement that returns result data set (such as select), use query or its convenient versions queryRow and queryScalar.
If an SQL statement returns results (such as a SELECT SQL), the results can be accessed via the returned TDbDataReader.
TDbCommand supports SQL statment preparation and parameter binding. Call bindParameter to bind a PHP variable to a parameter in SQL. Call bindValue to bind a value to an SQL parameter. When binding a parameter, the SQL statement is automatically prepared. You may also call prepare to explicitly prepare an SQL statement.
Class hierarchy
Author: Qiang Xue <qiang.xue@gmail.com>Since: 3.0
public
|
|
public
|
|
public
|
bindParameter(mixed $name, mixed &$value[, null|int $dataType = null ][, null|int $length = null ]) : mixed
Binds a parameter to the SQL statement to be executed.
|
public
|
bindValue(mixed $name, mixed $value[, null|int $dataType = null ]) : mixed
Binds a value to a parameter.
|
public
|
|
public
|
execute() : int
Executes the SQL statement.
This method is meant only for executing non-query SQL statement. No result set will be returned. |
public
|
|
public
|
|
public
|
|
public
|
|
public
|
prepare() : mixed
Prepares the SQL statement to be executed.
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
|
query() : TDbDataReader
Executes the SQL statement and returns query result.
This method is for executing an SQL query that returns result set. |
public
|
queryColumn() : array<string|int, mixed>
Executes the SQL statement and returns the first column of the result.
This is a convenient method of query when only the first column of data is needed. Note, the column returned will contain the first element in each row of result. |
public
|
queryRow([bool $fetchAssociative = true ]) : array<string|int, mixed>
Executes the SQL statement and returns the first row of the result.
This is a convenient method of query when only the first row of data is needed. |
public
|
queryScalar() : mixed
Executes the SQL statement and returns the value of the first column in the first row of data.
This is a convenient method of query when only a single scalar value is needed (e.g. obtaining the count of the records). |
public
|
setText(string $value) : mixed
Specifies the SQL statement to be executed.
Any previous execution will be terminated or cancel. |
\Prado\TComponent::GLOBAL_RAISE_EVENT_LISTENER |