DbCommand

Type
Class
Namespace
Craft
Inherits
Craft\DbCommand » CDbCommand (opens new window) » CComponent (opens new window)
Since
1.0

Class DbCommand

See also http://craftcms.com

View source (opens new window)

# Public Properties

Property Description
$params (opens new window) array (opens new window) – The parameters (name=>value) to be bound to the current query.

# Public Methods

Method Description
__call() (opens new window) Calls the named method which is not a class method.
__construct() Constructor
__get() (opens new window) Returns a property value, an event handler list or a behavior based on its name.
__isset() (opens new window) Checks if a property value is null.
__set() (opens new window) Sets value of a component property.
__sleep() (opens new window) Set the statement to null when serializing.
__unset() (opens new window) Sets a component property to be null.
addColumn()
addColumnAfter()
addColumnBefore()
addColumnFirst()
addForeignKey()
addOrder()
addPrimaryKey()
addSelect() Adds additional select columns.
alterColumn()
andWhere() Adds an additional "and where" condition.
asa() (opens new window) Returns the named behavior object.
attachBehavior() (opens new window) Attaches a behavior to this component.
attachBehaviors() (opens new window) Attaches a list of behaviors to the component.
attachEventHandler() (opens new window) Attaches an event handler to an event.
bindParam() (opens new window) Binds a parameter to the SQL statement to be executed.
bindValue() (opens new window) Binds a value to a parameter.
bindValues() (opens new window) Binds a list of values to the corresponding parameters.
buildQuery() (opens new window) Builds a SQL SELECT statement from the given query specification.
canGetProperty() (opens new window) Determines whether a property can be read.
canSetProperty() (opens new window) Determines whether a property can be set.
cancel() (opens new window) Cancels the execution of the SQL statement.
count() Returns the total number of rows matched by the query.
createIndex()
createTable() Adds id, dateCreated, date_update, and uid columns to $columns, packages up the column definitions into strings, and then passes it back to CDbCommand->createTable().
crossJoin()
delete()
detachBehavior() (opens new window) Detaches a behavior from the component.
detachBehaviors() (opens new window) Detaches all behaviors from the component.
detachEventHandler() (opens new window) Detaches an existing event handler.
disableBehavior() (opens new window) Disables an attached behavior.
disableBehaviors() (opens new window) Disables all behaviors attached to this component.
dropColumn()
dropForeignKey()
dropIndex()
dropPrimaryKey()
dropTable()
dropTableIfExists()
enableBehavior() (opens new window) Enables an attached behavior.
enableBehaviors() (opens new window) Enables all behaviors attached to this component.
evaluateExpression() (opens new window) Evaluates a PHP expression or callback under the context of this component.
execute() (opens new window) Executes the SQL statement.
from()
getConnection() (opens new window)
getDistinct() (opens new window) Returns a value indicating whether SELECT DISTINCT should be used.
getEventHandlers() (opens new window) Returns the list of attached event handlers for an event.
getFrom() (opens new window) Returns the FROM part in the query.
getGroup() (opens new window) Returns the GROUP BY part in the query.
getHaving() (opens new window) Returns the HAVING part in the query.
getJoin() (opens new window) Returns the join part in the query.
getJoinedTables() Returns the tables that have been joined.
getLimit() (opens new window) Returns the LIMIT part in the query.
getOffset() (opens new window) Returns the OFFSET part in the query.
getOrder() (opens new window) Returns the ORDER BY part in the query.
getPdoStatement() (opens new window)
getSelect() (opens new window) Returns the SELECT part in the query.
getText() (opens new window)
getUnion() (opens new window) Returns the UNION part in the query.
getWhere() (opens new window) Returns the WHERE part in the query.
group() (opens new window) Sets the GROUP BY part of the query.
hasEvent() (opens new window) Determines whether an event is defined.
hasEventHandler() (opens new window) Checks whether the named event has attached handlers.
hasProperty() (opens new window) Determines whether a property is defined.
having()
insert()
insertAll()
insertOrUpdate()
isJoined() Returns whether a given table has been joined in this query.
join()
leftJoin()
limit() (opens new window) Sets the LIMIT part of the query.
naturalJoin()
naturalLeftJoin()
naturalRightJoin()
offset() (opens new window) Sets the OFFSET part of the query.
orWhere() Adds an additional "or where" condition.
order() (opens new window) Sets the ORDER BY part of the query.
prepare() (opens new window) Prepares the SQL statement to be executed.
query() (opens new window) Executes the SQL statement and returns query result.
queryAll() (opens new window) Executes the SQL statement and returns all rows.
queryColumn() (opens new window) Executes the SQL statement and returns the first column of the result.
queryRow() (opens new window) Executes the SQL statement and returns the first row of the result.
queryScalar() (opens new window) Executes the SQL statement and returns the value of the first column in the first row of data.
raiseEvent() (opens new window) Raises an event.
renameColumn()
renameTable()
replace()
reset() (opens new window) Cleans up the command and prepares for building a new query.
rightJoin()
select() (opens new window) Sets the SELECT part of the query.
selectDistinct() (opens new window) Sets the SELECT part of the query with the DISTINCT flag turned on.
setDistinct() (opens new window) Sets a value indicating whether SELECT DISTINCT should be used.
setFetchMode() (opens new window) Set the default fetch mode for this statement
setFrom() (opens new window) Sets the FROM part in the query.
setGroup() (opens new window) Sets the GROUP BY part in the query.
setHaving() (opens new window) Sets the HAVING part in the query.
setJoin() (opens new window) Sets the join part in the query.
setLimit() (opens new window) Sets the LIMIT part in the query.
setOffset() (opens new window) Sets the OFFSET part in the query.
setOrder() (opens new window) Sets the ORDER BY part in the query.
setSelect() (opens new window) Sets the SELECT part in the query.
setText() (opens new window) Specifies the SQL statement to be executed.
setUnion() (opens new window) Sets the UNION part in the query.
setWhere() (opens new window) Sets the WHERE part in the query.
truncateTable()
union() (opens new window) Appends a SQL statement using UNION operator.
update()
where()

# __construct()

Signature

public Craft\DbCommand __construct ( CDbConnection $connection, $query = null )

# addColumn()

View source (opens new window)

Arguments

  • $table
  • $column
  • $type

Returns

mixed

Signature

public mixed addColumn ( $table, $column, $type )

# addColumnAfter()

View source (opens new window)

Arguments

  • $table
  • $column
  • $type
  • $after

Returns

mixed

Signature

public mixed addColumnAfter ( $table, $column, $type, $after )

# addColumnBefore()

View source (opens new window)

Arguments

  • $table
  • $column
  • $type
  • $before

Returns

mixed

Signature

public mixed addColumnBefore ( $table, $column, $type, $before )

# addColumnFirst()

View source (opens new window)

Arguments

  • $table
  • $column
  • $type

Returns

mixed

Signature

public mixed addColumnFirst ( $table, $column, $type )

# addForeignKey()

View source (opens new window)

Arguments

Returns

integer (opens new window)

Signature

public integer addForeignKey ( $table, $columns, $refTable, $refColumns, $delete = null, $update = null )

# addOrder()

View source (opens new window)

Arguments

  • $columns (mixed)

Returns

Craft\DbCommand

Signature

public Craft\DbCommand addOrder ( $columns )

# addPrimaryKey()

Signature

public integer addPrimaryKey ( $table, $columns )

# addSelect()

Adds additional select columns.

View source (opens new window)

Arguments

Returns

Craft\DbCommand

Signature

public Craft\DbCommand addSelect ( $columns = '*' )

# alterColumn()

Signature

public integer alterColumn ( $table, $column, $type, $newName = null, $after = null )

# andWhere()

Adds an additional "and where" condition.

View source (opens new window)

Arguments

Returns

Craft\DbCommand

Signature

public Craft\DbCommand andWhere ( $conditions, $params = [] )

# count()

Returns the total number of rows matched by the query.

View source (opens new window)

Arguments

Returns

integer (opens new window) – The total number of rows matched by the query.

Signature

public integer count ( $column )

# createIndex()

Signature

public integer createIndex ( $table, $columns, $unique = false )

# createTable()

Adds id, dateCreated, date_update, and uid columns to $columns, packages up the column definitions into strings, and then passes it back to CDbCommand->createTable().

View source (opens new window)

Arguments

Returns

integer (opens new window)

Signature

public integer createTable ( $table, $columns, $options = null, $addIdColumn = true, $addAuditColumns = true )

# crossJoin()

Signature

public Craft\DbCommand crossJoin ( $table )

# delete()

Signature

public integer delete ( $table, $conditions = '', $params = [] )

# dropColumn()

Signature

public integer dropColumn ( $table, $column )

# dropForeignKey()

Signature

public integer dropForeignKey ( $table, $columns )

# dropIndex()

Signature

public integer dropIndex ( $table, $columns, $unique = false )

# dropPrimaryKey()

Signature

public integer dropPrimaryKey ( $table, $columns )

# dropTable()

Signature

public integer dropTable ( $table )

# dropTableIfExists()

Signature

public integer dropTableIfExists ( $table )

# from()

Signature

public CDbCommand from ( $tables )

# getJoinedTables()

Returns the tables that have been joined.

View source (opens new window)

Returns

array (opens new window)

Signature

public array getJoinedTables ( )

# having()

View source (opens new window)

Arguments

Returns

Craft\DbCommand

Signature

public Craft\DbCommand having ( $conditions, $params = [] )

# insert()

Signature

public integer insert ( $table, $columns, $includeAuditColumns = true )

# insertAll()

Signature

public integer insertAll ( $table, $columns, $rows, $includeAuditColumns = true )

# insertOrUpdate()

Signature

public integer insertOrUpdate ( $table, $keyColumns, $updateColumns, $includeAuditColumns = true )

# isJoined()

Returns whether a given table has been joined in this query.

View source (opens new window)

Arguments

Returns

boolean (opens new window)

Signature

public boolean isJoined ( $table )

# join()

Signature

public Craft\DbCommand join ( $table, $conditions, $params = [] )

# leftJoin()

Signature

public Craft\DbCommand leftJoin ( $table, $conditions, $params = [] )

# naturalJoin()

Signature

public Craft\DbCommand naturalJoin ( $table )

# naturalLeftJoin()

Signature

public Craft\DbCommand naturalLeftJoin ( $table )

# naturalRightJoin()

Signature

public CDbCommand naturalRightJoin ( $table )

# orWhere()

Adds an additional "or where" condition.

View source (opens new window)

Arguments

Returns

Craft\DbCommand

Signature

public Craft\DbCommand orWhere ( $conditions, $params = [] )

# renameColumn()

View source (opens new window)

Arguments

  • $table
  • $name
  • $newName

Returns

integer (opens new window)

Signature

public integer renameColumn ( $table, $name, $newName )

# renameTable()

Signature

public integer renameTable ( $table, $newName )

# replace()

Signature

public integer replace ( $table, $column, $find, $replace )

# rightJoin()

Signature

public Craft\DbCommand rightJoin ( $table, $conditions, $params = [] )

# truncateTable()

Signature

public integer truncateTable ( $table )

# update()

Signature

public integer update ( $table, $columns, $conditions = '', $params = [], $includeAuditColumns = true )

# where()

View source (opens new window)

Arguments

Returns

Craft\DbCommand

Signature

public Craft\DbCommand where ( $conditions, $params = [] )