PRADO Component Framework for PHP 5
  • Home
  • About
  • Testimonials
  • Demos
  • Download
  • Documentation
  • Forum
  • Development
  • Tutorials
  • Class Docs
  • API Manual
  • Wiki

Packages

  • None
  • System
    • Caching
    • Collections
    • Data
      • ActiveRecord
        • Relations
        • Scaffold
          • InputBuilder
      • Commom
        • Sqlite
      • Common
        • Mssql
        • Mysql
        • Oracle
        • Pgsql
        • Sqlite
      • DataGateway
      • SqlMap
        • Configuration
        • Statements
    • Exceptions
    • I18N
    • IO
    • Security
    • Util
    • Web
      • Javascripts
      • Services
      • UI
        • ActiveControls
        • WebControls
    • Xml
  • Wsat
    • pages
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo

Class 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 setText Text.

To execute a non-query SQL (such as insert, delete, update), call TDbCommand::execute(). To execute an SQL statement that returns result data set (such as select), use TDbCommand::query() or its convenient versions TDbCommand::queryRow() and TDbCommand::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 TDbCommand::bindParameter() to bind a PHP variable to a parameter in SQL. Call TDbCommand::bindValue() to bind a value to an SQL parameter. When binding a parameter, the SQL statement is automatically prepared. You may also call TDbCommand::prepare() to explicitly prepare an SQL statement.

TComponent
Extended by TDbCommand
Package: System\Data
Copyright: Copyright © 2005-2014 PradoSoft
License: http://www.pradosoft.com/license/
Author: Qiang Xue <qiang.xue@gmail.com>
Since: 3.0
Located at Data/TDbCommand.php
Methods summary
public
# __construct( TDbConnection $connection, string $text )

Constructor.

Constructor.

Parameters

$connection
TDbConnection
the database connection
$text
string
the SQL statement to be executed

Overrides

TComponent::__construct()
public
# __sleep( )

Set the statement to null when serializing.

Set the statement to null when serializing.

Overrides

TComponent::__sleep()
public string
# getText( )

Returns

string
the SQL statement to be executed
public
# setText( string $value )

Specifies the SQL statement to be executed. Any previous execution will be terminated or cancel.

Specifies the SQL statement to be executed. Any previous execution will be terminated or cancel.

Parameters

$value
string
the SQL statement to be executed
public TDbConnection
# getConnection( )

Returns

TDbConnection
the connection associated with this command
public PDOStatement
# getPdoStatement( )

Returns

PDOStatement
the underlying PDOStatement for this command It could be null if the statement is not prepared yet.
public
# 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.

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
# cancel( )

Cancels the execution of the SQL statement.

Cancels the execution of the SQL statement.

public
# bindParameter( mixed $name, mixed & $value, integer $dataType = null, integer $length = null )

Binds a parameter to the SQL statement to be executed.

Binds a parameter to the SQL statement to be executed.

Parameters

$name
mixed
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. Unlike TDbCommand::bindValue(), the variable is bound as a reference and will only be evaluated at the time that TDbCommand::execute() or TDbCommand::query() is called.
$value
mixed
Name of the PHP variable to bind to the SQL statement parameter
$dataType
integer
SQL data type of the parameter
$length
integer
length of the data type

See

http://www.php.net/manual/en/function.PDOStatement-bindParam.php
public
# bindValue( mixed $name, mixed $value, integer $dataType = null )

Binds a value to a parameter.

Binds a value to a parameter.

Parameters

$name
mixed
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.
$value
mixed
The value to bind to the parameter
$dataType
integer
SQL data type of the parameter

See

http://www.php.net/manual/en/function.PDOStatement-bindValue.php
public integer
# execute( )

Executes the SQL statement. This method is meant only for executing non-query SQL statement. No result set will be returned.

Executes the SQL statement. This method is meant only for executing non-query SQL statement. No result set will be returned.

Returns

integer
number of rows affected by the execution.

Throws

TDbException
execution failed
public String
# getDebugStatementText( )

Returns

String
prepared SQL text for debugging purposes.
public TDbDataReader
# query( )

Executes the SQL statement and returns query result. This method is for executing an SQL query that returns result set.

Executes the SQL statement and returns query result. This method is for executing an SQL query that returns result set.

Returns

TDbDataReader
the reader object for fetching the query result

Throws

TDbException
execution failed
public array
# queryRow( boolean $fetchAssociative = true )

Executes the SQL statement and returns the first row of the result. This is a convenient method of TDbCommand::query() when only the first row of data is needed.

Executes the SQL statement and returns the first row of the result. This is a convenient method of TDbCommand::query() when only the first row of data is needed.

Parameters

$fetchAssociative
boolean
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).

Returns

array
the first row of the query result, false if no result.

Throws

TDbException
execution failed
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 TDbCommand::query() when only a single scalar value is needed (e.g. obtaining the count of the records).

Executes the SQL statement and returns the value of the first column in the first row of data. This is a convenient method of TDbCommand::query() when only a single scalar value is needed (e.g. obtaining the count of the records).

Returns

mixed
the value of the first column in the first row of the query result. False is returned if there is no value.

Throws

TDbException
execution failed
public array
# queryColumn( )

Executes the SQL statement and returns the first column of the result. This is a convenient method of TDbCommand::query() when only the first column of data is needed. Note, the column returned will contain the first element in each row of result.

Executes the SQL statement and returns the first column of the result. This is a convenient method of TDbCommand::query() when only the first column of data is needed. Note, the column returned will contain the first element in each row of result.

Returns

array
the first column of the query result. Empty array if no result.

Throws

TDbException
execution failed

Since

3.1.2
Methods inherited from TComponent
__call(), __destruct(), __get(), __isset(), __set(), __unset(), __wakeup(), addParsedObject(), asa(), attachBehavior(), attachBehaviors(), attachClassBehavior(), attachEventHandler(), canGetProperty(), canSetProperty(), clearBehaviors(), createdOnTemplate(), detachBehavior(), detachBehaviors(), detachClassBehavior(), detachEventHandler(), disableBehavior(), disableBehaviors(), enableBehavior(), enableBehaviors(), evaluateExpression(), evaluateStatements(), fxAttachClassBehavior(), fxDetachClassBehavior(), getAutoGlobalListen(), getBehaviorsEnabled(), getClassHierarchy(), getEventHandlers(), getListeningToGlobalEvents(), getSubProperty(), hasEvent(), hasEventHandler(), hasProperty(), isa(), listen(), raiseEvent(), setSubProperty(), unlisten()
Constants inherited from TComponent
GLOBAL_RAISE_EVENT_LISTENER
Terms of Service | Contact Us
PRADO v3.2.4 API Manual API documentation generated by ApiGen 2.8.0
Copyright © 2006-2014 by the PRADO Group.
Powered by PRADO