$error
$error :
string
SQL
SQL abstraction layer for using MySQL.
subQuery( stmt, alias = FALSE, from = TRUE, clause = FALSE) :
Create a subquery from a SQL statement
stmt | Pre-defined SQL stmt (which may be a subquery itself) |
|
alias | Boolean table alias sometimes required for subquery SELECT statements. Default is FALSE |
|
from | TRUE If FALSE, don't add the initial 'FROM' |
|
clause | Default is FALSE. If TRUE, add all conditions, joins, groupBy, orderBy etc. clauses |
subQueryFields(mixed||string|int fields, subquery, alias = FALSE, clause = FALSE, distinct = FALSE, tidy = TRUE) :
Create a subquery from SQL fields
If $alias is FALSE: 'FROM (SELECT $distinct $field $subquery $clause)' If $alias is TRUE: 'FROM (SELECT $distinct $field $subquery $clause) AS '
mixed||string|int | fields | |
subquery | Formatted subquery string |
|
alias | Boolean table alias sometimes required for subquery SELECT statements. Default is FALSE |
|
clause | Default is FALSE. If TRUE, add all conditions, joins, groupBy, orderBy etc. clauses |
|
distinct | Default is FALSE |
|
tidy | Format fields for SQL queries. Default is TRUE |
select(mixed||string|int tables, fields, distinct = FALSE, tidyFields = TRUE, alias = FALSE, clause = FALSE) :
Execute SELECT statement
mixed||string|int | tables | |
fields | Array of fields or can be '*' |
|
distinct | Default is FALSE |
|
tidyFields | Format fields for SQL. Default is TRUE |
|
alias | Default is FALSE |
|
clause | Default is FALSE |
recordset
selectFirstRow(mixed||string|int tables, fields, distinct = FALSE, tidyFields = TRUE, alias = FALSE, clause = FALSE) : mixed||string|int
Execute SELECT statement and return the first row
mixed||string|int | tables | |
fields | Array of fields or can be '*' |
|
distinct | Default is FALSE |
|
tidyFields | Format fields for SQL. Default is TRUE |
|
alias | Default is FALSE |
|
clause | Default is FALSE |
selectFirstField(mixed||string|int tables, fields, distinct = FALSE, tidyFields = TRUE, alias = FALSE, clause = FALSE) :
Execute SELECT statement and return the first field of the first row
mixed||string|int | tables | |
fields | Array of fields or can be '*' |
|
distinct | Default is FALSE |
|
tidyFields | Format fields for SQL. Default is TRUE |
|
alias | Default is FALSE |
|
clause | Default is FALSE |
selectNoExecute(mixed||string|int tables, fields, distinct = FALSE, tidyFields = TRUE, clause = FALSE, alias = FALSE) :
Create a SELECT statement without executing
Either: "SELECT DISTINCT $field FROM $table $alias $clause" or "SELECT $field FROM $table $alias $clause"
mixed||string|int | tables | |
fields | Array of fields or '*' |
|
distinct | Default is FALSE |
|
tidyFields | Format fields. Default is TRUE |
|
clause | Default is FALSE |
|
alias | Default is FALSE |
selectMax( table, maxField, alias = FALSE, mixed||string|int otherFields = FALSE, subQuery = FALSE) :
Execute SELECT MAX() statement
table | ||
maxField | ||
alias | Default is FALSE |
|
mixed||string|int | otherFields | Other fields to add to the query. Default is FALSE |
subQuery | Default is FALSE |
recordset
selectCounts( table, field, mixed||string|int otherFields = FALSE, subQuery = FALSE, group = TRUE, clause = FALSE, distinct = FALSE) :
Execute a "SELECT $field, COUNT($field) AS count $otherFields $table $subQuery" statement
table | ||
field | ||
mixed||string|int | otherFields | Other fields to add to the query. Default is FALSE |
subQuery | Default is FALSE |
|
group | Default is TRUE |
|
clause | Default is FALSE |
|
distinct | Default is FALSE |
recordset
selectCountsNoExecute( table, field, mixed||string|int otherFields = FALSE, subQuery = FALSE, group = TRUE, clause = FALSE, distinct = FALSE) :
Create a "SELECT $field, COUNT($field) AS count $otherFields $table $subQuery $clause" statement without executing
table | ||
field | ||
mixed||string|int | otherFields | Other fields to add to the query. Default is FALSE |
subQuery | Default is FALSE |
|
group | Default is TRUE |
|
clause | Default is FALSE |
|
distinct | Default is FALSE |
selectCountDistinctField( table, field, subQuery = FALSE, clause = FALSE) :
Execute a "SELECT COUNT(DISTINCT $field) AS count $table $subQuery" statement
NB 'count' field in the recordset
table | ||
field | ||
subQuery | Default is FALSE |
|
clause | Default is FALSE |
recordset
selectCountDistinctFieldNoExecute( table, field, subQuery = FALSE, clause = FALSE) :
Create a "SELECT COUNT(DISTINCT $field) AS count $table $subQuery $clause" statement without executing
NB 'count' field in the recordset
table | ||
field | ||
subQuery | Default is FALSE |
|
clause | Default is FALSE |
selectFromSubQuery(mixed||string|int tables, fields, subQuery, distinct = FALSE, tidy = TRUE, clause = FALSE) :
Execute a SELECT statement with a subquery
If $tables is FALSE, statement is "SELECT $field $subQuery" else it is "SELECT $field $subQuery $tables"
mixed||string|int | tables | |
fields | Array of fields or '*' |
|
subQuery | ||
distinct | Default is FALSE |
|
tidy | Format fields. Default is TRUE |
|
clause | Default is FALSE |
recordset
selectNoExecuteFromSubQuery(mixed||string|int tables, fields, subQuery, distinct = FALSE, tidy = TRUE, clause = FALSE) :
Create a SELECT statement with a subquery without executing
If $tables is FALSE, statement is "SELECT $field $subQuery $clause" else it is "SELECT $field $subQuery $tables $clause"
mixed||string|int | tables | |
fields | Array of fields or '*' |
|
subQuery | ||
distinct | Default is FALSE |
|
tidy | Format fields. Default is TRUE |
|
clause | Default is FALSE |
recordset
updateTimestamp( table, mixed||string|int updateArray) :
Execute an UPDATE statement for an array of fields, setting the timestamp of a field
If there is no value for a $updateArray key, the timestamp is set to CURRENT_TIMESTAMP
table | ||
mixed||string|int | updateArray |
multiUpdate( table, setField, conditionField, mixed||string|int updateArray, mixed||string|int extraConditions = FALSE) :
Create and execute a multiple update on one table
table | ||
setField | ||
conditionField | ||
mixed||string|int | updateArray | |
mixed||string|int | extraConditions | Optional array of formatted conditions joined with an AND to the IN clause |
formatConditions( condition, notEqual = =, returnString = FALSE, doubleParentheses = FALSE) :
Set up the SQL conditions for the next query.
Conditions should be set before almost every SQL query. After the query is executed, the conditions are deleted automatically. Multiple conditions are joined with $this->conditionSeparator which by default is set to $this->and (it could be $this->or). $this->conditionSeparator is reset automatically after each query back to $this->and.
condition | Array of field => condition conditions or formatted condition string |
|
notEqual | Default is '=' |
|
returnString | Default is FALSE. If TRUE, don't set the condition but return a formatted condition string instead |
|
doubleParentheses | Default is FALSE |
Optional return
formatConditionsOneField( condition, field, notEqual = FALSE, tidy = TRUE, doubleParentheses = FALSE, alias = FALSE, returnString = FALSE) :
Format multiple conditions for one field using ' OR '
Conditions should be set before almost every SQL query. After the query is executed, the conditions are reset automatically. Multiple conditions are joined with $this->or ($this->conditionSeparator is ignored).
condition | Array of conditions or formatted condition string |
|
field | ||
notEqual | Default is FALSE |
|
tidy | Format the field for the database type. Default is TRUE. |
|
doubleParentheses | Place double, rather than single, parentheses around the condition. Default is FALSE. |
|
alias | $field is an alias in SQL so should have quotes instead of backticks. Default is FALSE. |
|
returnString | Default is FALSE. If TRUE, don't set the condition but return a formatted condition string instead |
dateDiffRatio( field, denominator, alias = FALSE, aggregateFunction, round = 3, otherFields = FALSE, group = FALSE) :
Return a ratio alias of $field / number days since e.g. resource added.
field | (e.g. 'resourcemiscAccesses', or 'resourceattachmentDownloads') |
|
denominator | (e.g. 'resourcetimestampTimestampAdd') |
|
alias | Default is FALSE |
|
aggregateFunction | Default is ''. If <> '', insert an Aggregate Function of the same name of multiple $fields |
|
round | Default is 3 |
|
otherFields | FALSE (default) or comma-delimited list of database fields to include in the GROUP BY |
|
group | FALSE (default) or GROUP BY $field and $otherFields |
caseWhen( subject, test, result, default = FALSE, tidy = TRUE, alias = FALSE) :
Create a CASE WHEN() THEN clause.
$subject can be an array. This allows multiple WHEN $subject:key THEN $subject:value to be part of the CASE statement. If $subject is an array, $test and $result are ignored ($tidy is still tested regarding formatting or not of $default) and the keys and values of $subject should already be formatted and tidied for SQL: e.g. subject['subject = test'] => result;
subject | (string or array) |
|
test | ||
result | ||
default | Default is FALSE |
|
tidy | Default is TRUE. If TRUE, format fields for database type |
|
alias | Default is FALSE |
innerJoin( table, left, right = FALSE, tidy = TRUE) :
Create a INNER JOIN clause on a table
Clauses are stored in $this->join array for use at the next query after which the array is emptied. You should set up your join statements before each query.
table | ||
left | ||
right | Default is FALSE |
|
tidy | Default is TRUE. If TRUE, format fields for database type |
innerJoinSubQuery( subQuery, left, right = FALSE, tidy = TRUE) :
Create a INNER JOIN clause on a subquery
Clauses are stored in $this->join array for use at the next query after which the array is emptied. You should set up your join statements before each query.
subQuery | ||
left | ||
right | Default is FALSE |
|
tidy | Default is TRUE. If TRUE, format fields for database type |
innerJoinGeneric( joinedMember, left, right = FALSE, tidy = TRUE) :
Create a INNER JOIN clause (generic)
Clauses are stored in $this->join array for use at the next query after which the array is emptied. You should set up your join statements before each query.
joinedMember | (Name of a table, Name of a view, subquery...) |
|
left | ||
right | Default is FALSE |
|
tidy | Default is TRUE. If TRUE, format fields for database type |
leftJoin( table, left, right = FALSE, tidy = TRUE) :
Create a LEFT JOIN clause on a table
Clauses are stored in $this->join array for use at the next query after which the array is emptied. You should set up your join statements before each query.
table | ||
left | ||
right | Default is FALSE |
|
tidy | Default is TRUE. If TRUE, format fields for database type |
leftJoinSubQuery( subQuery, left, right = FALSE, tidy = TRUE) :
Create a LEFT JOIN clause on a subquery
Clauses are stored in $this->join array for use at the next query after which the array is emptied. You should set up your join statements before each query.
subQuery | ||
left | ||
right | Default is FALSE |
|
tidy | Default is TRUE. If TRUE, format fields for database type |
leftJoinCondition( table, left, right = FALSE, condition = FALSE, and = TRUE, tidy = TRUE) :
Create a LEFT JOIN clause with additional condition string
Clauses are stored in $this->join array for use at the next query after which the array is emptied. You should set up your join statements before each query.
table | ||
left | ||
right | Default is FALSE |
|
condition | Default is FALSE |
|
and | Default is TRUE. If TRUE, prefix SQL 'AND' to $condition |
|
tidy | Default is TRUE. If TRUE, format fields for database type |
leftJoinGeneric( joinedMember, left, right = FALSE, tidy = TRUE) :
Create a LEFT JOIN clause (generic)
Clauses are stored in $this->join array for use at the next query after which the array is emptied. You should set up your join statements before each query.
joinedMember | (Name of a table, Name of a view, subquery...) |
|
left | ||
right | Default is FALSE |
|
tidy | Default is TRUE. If TRUE, format fields for database type |
orderBy( field, tidy = TRUE, removeBraces = TRUE) :
Create an ORDER BY clause
Clauses are stored in $this->order array for use at the next query after which the array is emptied. You should set up your order statements before each query.
field | ||
tidy | Default is TRUE. If TRUE, format fields for database type |
|
removeBraces | Default is TRUE. If TRUE, remove {...} braces |
orderByCollate( field, tidy = TRUE) :
Create an ORDER BY clause with additional COLLATION for UTF8
Clauses are stored in $this->order array for use at the next query after which the array is emptied. You should set up your order statements before each query.
field | ||
tidy | Default is TRUE. If TRUE, format fields for database type |
groupBy( field, tidy = TRUE, having = FALSE) :
Create a GROUP BY clause
Clauses are stored in $this->group array for use at the next query after which the array is emptied. You should set up your group statements before each query.
field | ||
tidy | Default is TRUE. If TRUE, format fields for database type |
|
having | Default is FALSE. If TRUE, group by clause has ' HAVING $having' appended to it. |
limit( limit, offset, return = FALSE) :
Create a LIMIT clause
Clauses are stored in the $this->limit string for use at the next query after which the string is reset. You should set up your limit statement before each query.
limit | ||
offset | ||
return | If TRUE, return the limit statement rather than setting it. Default is FALSE |
count( field, operator = FALSE, comparison = FALSE, distinct = FALSE, alias = FALSE) :
Create a COUNT() clause
field | Database field to count |
|
operator | Optional =, !=, >, <. Default is FALSE |
|
comparison | Comparison following $operator. Default is FALSE |
|
distinct | TRUE/FALSE (default). COUNT(DISTINCT |
|
alias | COUNT( |
countAlpha( order, subQuery = FALSE, mixed||string|int conditions = array(), mixed||string|int joins = array(), mixed||string|int conditionsOneField = array(), table = resource, tableJoin = resourceId) :
Create the SQL SELECT statement for counting resources/initial character of creator or title when using alphabetic paging.
A-Z for Latin characters, '??' for all other characters and '#' for NULL resourcecreatorCreatorSurname fields
order | ('creator' or 'title') |
|
subQuery | Optional subquery to be added to this statement |
|
mixed||string|int | conditions | Array of conditions to SQL |
mixed||string|int | joins | Array of table joins to SQL (array(table => array(rightField, leftField)) |
mixed||string|int | conditionsOneField | Array of conditions to SQL (formatConditionsOneField) |
table | default is 'resource' |
|
tableJoin | default is 'resourceId' |