Methods summary
public
|
#
__construct( string $table = null, string $alias = null )
Constructor
Parameters
- $table
- The base table to select from
- $alias
- The alias for the table
|
public
object
|
#
from( string $table, string $alias = null )
Table to SELECT
Parameters
- $table
- The table name
- $alias
- The table alias
Returns
object QueryBuilder
|
public
object
|
#
fields( string $alias, array $fields = array() )
Add fields to SELECT
Parameters
- $alias
- The table alias
- $fields
- Array of field names
Returns
object QueryBuilder
|
public
object
|
#
field( string $field, array $alias = null )
Add field to SELECT
Parameters
- $field
- The field name
- $alias
- The alias for the field name
Returns
object QueryBuilder
|
public
object
|
#
join( string $table, string $alias, string $condition, string $type = 'INNER' )
Add a table to join
Parameters
- $table
- The table name
- $alias
- The alias for the table
- $condition
- The join condition e.g., t1.pk = t2.fk
- $type
- INNER, LEFT, RIGHT or OUTER
Returns
object QueryBuilder
|
public
object
|
#
leftJoin( string $table, string $alias, string $condition )
Add a table to perform left join
Add a table to perform left join
Parameters
- $table
- The table name
- $alias
- The alias for the table
- $condition
- The join condition e.g., t1.pk = t2.fk
Returns
object QueryBuilder
|
public
object
|
#
rightJoin( string $table, string $alias, string $condition )
Add a table to perform right join
Add a table to perform right join
Parameters
- $table
- The table name
- $alias
- The alias for the table
- $condition
- The join condition e.g., t1.pk = t2.fk
Returns
object QueryBuilder
|
public
object
|
#
outerJoin( string $table, string $alias, string $condition )
Add a table to perform outer join
Add a table to perform outer join
Parameters
- $table
- The table name
- $alias
- The alias for the table
- $condition
- The join condition e.g., t1.pk = t2.fk
Returns
object QueryBuilder
|
public
object
|
#
where( array|null $condition = null )
Alias of andWhere()
Create WHERE ... AND condition
Alias of andWhere()
Create WHERE ... AND condition
Parameters
- $condition
- The array of conditions
Returns
object QueryBuilder
|
public
object
|
#
andWhere( array|null $condition = null )
Create WHERE ... AND condition
Create WHERE ... AND condition
Parameters
- $condition
The array of conditions
array(
'fieldName1' => $value1,
'fieldName2 >=' => $value2,
'fieldName3 => NULL
)
OR
array(
'fieldName1' => $value1,
'fieldName2 >=' => $value2,
'fieldName3 => NULL,
'$or' => array(
'fieldName4' => array(1, 2, 3)
'fieldName4 <' => 10
)
)
Returns
object QueryBuilder
|
public
object
|
#
orWhere( array|null $condition = null )
Create WHERE ... OR condition
Create WHERE ... OR condition
Parameters
- $condition
The array of conditions
array(
'fieldName1' => $value1,
'fieldName2 >=' => $value2,
'fieldName3 => NULL
)
OR
array(
'fieldName1' => $value1,
'fieldName2 >=' => $value2,
'fieldName3 => NULL,
'$and' => array(
'fieldName4' => array(1, 2, 3)
'fieldName4 <' => 10
)
)
Returns
object QueryBuilder
|
public
object
|
#
condition( string $field, mixed $value )
Create simple WHERE condition with field/value assignment
Create simple WHERE condition with field/value assignment
Parameters
- $field
- The field name
- $value
The value to check against the field name
$qb = db_select('post', 'p')
->orWhere()
->condition('catId', 1)
->condition('catId', 2);
Returns
object QueryBuilder
|
public
object
|
#
orderBy( string $field, string $sort = 'ASC' )
Add ORDER BY clause
Parameters
- $field
- The field name to sort
- $sort
- ASC or DESC
Returns
object QueryBuilder
|
public
object
|
#
groupBy( string $field )
Add GROUP BY clause
Parameters
Returns
object QueryBuilder
|
public
object
|
#
having( array $condition )
Create HAVING ... condition
Create HAVING ... condition
Parameters
- $condition
The array of conditions
array(
'fieldName1' => $value1,
'fieldName2 >=' => $value2,
'fieldName3 => NULL
)
OR
array(
'fieldName1' => $value1,
'fieldName2 >=' => $value2,
'fieldName3 => NULL,
'$or' => array(
'fieldName4' => array(1, 2, 3)
'fieldName4 <' => 10
)
)
Returns
object QueryBuilder
|
public
object
|
#
andHaving( array $condition )
Create AND HAVING ... condition
Create AND HAVING ... condition
Parameters
- $condition
- The array of conditions
Returns
object QueryBuilder
See
|
public
object
|
#
orHaving( array $condition = array() )
Create OR HAVING ... condition
Create OR HAVING ... condition
Parameters
- $condition
- The array of conditions
Returns
object QueryBuilder
See
|
public
object
|
#
limit( )
Add LIMIT clause
Returns
object QueryBuilder
|
public
object
|
#
count( string $field = null, string $alias = null )
Add COUNT(*) or COUNT(field)
Add COUNT(*) or COUNT(field)
Parameters
- $field
- The field name
- $alias
- The alias field name to retrieve
Returns
object QueryBuilder
|
public
object
|
#
max( string $field, string $alias = null )
Add MAX(field)
Parameters
- $field
- The field name
- $alias
- The alias field name to retrieve
Returns
object QueryBuilder
|
public
object
|
#
min( string $field, string $alias = null )
Add MIN(field)
Parameters
- $field
- The field name
- $alias
- The alias field name to retrieve
Returns
object QueryBuilder
|
public
object
|
#
sum( string $field, string $alias = null )
Add SUM(field)
Parameters
- $field
- The field name
- $alias
- The alias field name to retrieve
Returns
object QueryBuilder
|
public
object
|
#
avg( string $field, string $alias = null )
Add AVG(field)
Parameters
- $field
- The field name
- $alias
- The alias field name to retrieve
Returns
object QueryBuilder
|
protected
object
|
#
setAggregate( string $name, string $field = null, string $alias = null )
Aggregation
Parameters
- $name
- The function name COUNT, MAX, MIN, SUM, AVG, etc.
- $field
- The field name
- $alias
- The alias field name to retrieve
Returns
object QueryBuilder
|
protected
object
|
#
buildSQL( )
Build SQL
Returns
object QueryBuilder
|
public
boolean|resource
|
#
execute( )
Execute the query
Returns
boolean|resource The result
|
public
integer
|
#
getNumRows( )
Get the number of rows in the query result
Get the number of rows in the query result
Returns
integer Returns the number of rows in the result set.
|
public
mixed
|
#
fetchRow( integer $resultType = LC_FETCH_OBJECT )
Fetch a query result row
Parameters
- $resultType
The optional constant indicating what type of array should be produced.
The possible values for this parameter are the constants
LC_FETCH_OBJECT, LC_FETCH_ASSOC, or LC_FETCH_ARRAY.
Default to LC_FETCH_OBJECT.
Returns
mixed
|
public
array|null
|
#
getResult( )
Perform a query on the database and return the array of all results
Perform a query on the database and return the array of all results
Returns
array|null The result array of objects.
If the result not found, return null.
|
public
object|null
|
#
getSingleResult( )
Perform a query on the database and return the result object
Perform a query on the database and return the result object
Returns
object|null The result object
If the result not found, return null.
|
public
mixed
|
#
fetch( )
Perform a query on the database and fetch one field only
Perform a query on the database and fetch one field only
Returns
mixed The result
If the result not found, return null.
|
public
string
|
#
getSQL( )
Get the built SQL
Returns
string
|
public
string
|
#
getReadySQL( )
Get the built SQL with the values replaced
Get the built SQL with the values replaced
Returns
string
|
public static
boolean
|
#
validateName( string $name )
Validate table name or field name
Validate table name or field name
Parameters
- $name
- The table name or field name to be validated
Returns
boolean
|
public static
string
|
#
quote( string $name )
Quote table name and field name
Quote table name and field name
Parameters
- $name
- The table name or field name or table.field
Returns
string
|
public static
string
|
#
raw( string $expression )
Create raw expression string
Create raw expression string
Parameters
Returns
string
|
public static
array
|
#
buildCondition( array $cond = array(), string $type = 'AND' )
Build the SQL WHERE clause from the various condition arrays
Build the SQL WHERE clause from the various condition arrays
Parameters
- $cond
The condition array, for example
array(
'fieldName1' => $value1,
'fieldName2 >=' => $value2,
'fieldName3 => NULL
)
- $type
- The condition type "AND" or "OR"; Default is "AND"
Returns
array The built condition WHERE AND/OR
[0] string The built condition WHERE AND/OR clause
[1] array The values to bind in the condition
|
public static
|
|
public static
array
|
#
getBindValues( )
Get bind values
Returns
array
|