- Home
- About
- Testimonials
- Demos
- Download
- Documentation
- Blogs
- Forum
- Support

Packages: default System System.Caching System.Collections System.Data System.Data.ActiveRecord System.Data.ActiveRecord.Relations System.Data.ActiveRecord.Scaffold System.Data.ActiveReecord.Scaffold.InputBuilder System.Data.Commom.Sqlite System.Data.Common System.Data.Common.Mssql System.Data.Common.Mysql System.Data.Common.Oracle System.Data.Common.Pgsql System.Data.Common.Sqlite System.Data.DataGateway System.Data.SqlMap System.Data.SqlMap.Configuration System.Data.SqlMap.Statements System.Exceptions System.I18N System.IO System.Security System.Util System.Web System.Web.Services System.Web.UI System.Web.UI.ActiveControls System.Web.UI.WebControls System.Web.UI.WebControls.assets System.Xml Classes: TDataSourceConfig TDbColumnCaseMode TDbCommand TDbConnection TDbDataReader TDbNullConversionMode TDbTransaction |
Keyword
# Class TDbCommand
    TComponent
       |
       --TDbCommand
TDbCommand class. 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 Text. 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. Since: 3.0 Author: Qiang Xue <qiang.xue@gmail.com>
Constructor Summary
public | __construct Array Constructor.
Method Summary
void | bindParameter ( mixed $name, mixed &$value, int $dataType, int $length) Binds a parameter to the SQL statement to be executed.
void | bindValue ( mixed $name, mixed $value, int $dataType) Binds a value to a parameter.
void | cancel () Cancels the execution of the SQL statement.
integer | execute () Executes the SQL statement.
TDbConnection | getConnection ()
String | getDebugStatementText ()
PDOStatement | getPdoStatement ()
string | getText ()
void | prepare () Prepares the SQL statement to be executed.
TDbDataReader | query () Executes the SQL statement and returns query result.
array | queryColumn () Executes the SQL statement and returns the first column of the result.
array | queryRow ( boolean $fetchAssociative) Executes the SQL statement and returns the first row of the result.
mixed | queryScalar () Executes the SQL statement and returns the value of the first column in the first row of data.
void | setText ( string $value) Specifies the SQL statement to be executed.
void | __sleep () Set the statement to null when serializing.
Methods Inherited From TComponent
TComponent::addParsedObject(), TComponent::attachEventHandler(), TComponent::canGetProperty(), TComponent::canSetProperty(), TComponent::createdOnTemplate(), TComponent::detachEventHandler(), TComponent::evaluateExpression(), TComponent::evaluateStatements(), TComponent::getEventHandlers(), TComponent::getSubProperty(), TComponent::hasEvent(), TComponent::hasEventHandler(), TComponent::hasProperty(), TComponent::raiseEvent(), TComponent::setSubProperty(), TComponent::__get(), TComponent::__set()
Constructor Details
## __construct
public __construct | Array
Constructor.
Method Details
## bindParameter
public void bindParameter | (mixed $name , mixed &$value , int $dataType , int $length )
Binds a parameter to the SQL statement to be executed.
Input
mixed | $name | Parameter identifier. For a prepared statement using named placeholders, this will be a parameter name of the form :name. For a prepared statement using question mark placeholders, this will be the 1-indexed position of the parameter.
mixed | &$value | Name of the PHP variable to bind to the SQL statement parameter
int | $dataType | SQL data type of the parameter
int | $length | length of the data type
Output
Exception
## bindValue
public void bindValue | (mixed $name , mixed $value , int $dataType )
Binds a value to a parameter.
Input
mixed | $name | Parameter identifier. For a prepared statement using named placeholders, this will be a parameter name of the form :name. For a prepared statement using question mark placeholders, this will be the 1-indexed position of the parameter.
mixed | $value | The value to bind to the parameter
int | $dataType | SQL data type of the parameter
Output
Exception
## cancel
public void cancel | ()
Cancels the execution of the SQL statement.
Output
Exception
## execute
public integer execute | ()
Executes the SQL statement. This method is meant only for executing non-query SQL statement. No result set will be returned.
Output
integer | number of rows affected by the execution.
Exception
throws | TDbException execution failed
## getConnection
public TDbConnection getConnection | ()
Output
TDbConnection | the connection associated with this command
Exception
## getDebugStatementText
public String getDebugStatementText | ()
Output
String | prepared SQL text for debugging purposes.
Exception
## getPdoStatement
public PDOStatement getPdoStatement | ()
Output
PDOStatement | the underlying PDOStatement for this command It could be null if the statement is not prepared yet.
Exception
## getText
public string getText | ()
Output
string | the SQL statement to be executed
Exception
## prepare
public void prepare | ()
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.
Output
Exception
## query
public TDbDataReader query | ()
Executes the SQL statement and returns query result. This method is for executing an SQL query that returns result set.
Output
TDbDataReader | the reader object for fetching the query result
Exception
throws | TDbException execution failed
## queryColumn
public array queryColumn | ()
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.
Output
array | the first column of the query result. Empty array if no result.
Exception
throws | TDbException execution failed
## queryRow
public array queryRow | (boolean $fetchAssociative )
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.
Input
boolean | $fetchAssociative | whether the row should be returned as an associated array with column names as the keys or the array keys are column indexes (0-based).
Output
array | the first row of the query result, false if no result.
Exception
throws | TDbException execution failed
## queryScalar
public mixed queryScalar | ()
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).
Output
mixed | the value of the first column in the first row of the query result. False is returned if there is no value.
Exception
throws | TDbException execution failed
## setText
public void setText | (string $value )
Specifies the SQL statement to be executed. Any previous execution will be terminated or cancel.
Input
string | $value | the SQL statement to be executed
Output
Exception
## __sleep
public void __sleep | ()
Set the statement to null when serializing.
Output
Exception