\SQL

SQL

SQL abstraction layer for using MySQL.

Summary

Methods
Properties
Constants
__construct()
getNumberEngineVersion()
getStringEngineVersion()
close()
EnableFullGroupBySqlMode()
DisableFullGroupBySqlMode()
enableSqlMode()
disableSqlMode()
setSqlMode()
getMaxPacket()
queryNoExecute()
query()
queryNoError()
queryNoResult()
queryFetchFirstRow()
queryFetchFirstField()
resetSubs()
listFields()
listTables()
tableExists()
tableIsEmpty()
createTable()
numRows()
goToRow()
fetchRow()
fetchOne()
getFieldsProperties()
union()
subQuery()
subQueryFields()
select()
selectFirstRow()
selectFirstField()
selectNoExecute()
selectMax()
selectMin()
selectAverageDate()
selectCount()
selectCountMax()
selectCounts()
selectCountsNoExecute()
selectCountDistinctField()
selectCountDistinctFieldNoExecute()
selectCountFromSubquery()
selectCountFromSubqueryNoExecute()
selectWithExceptions()
selectNoExecuteWithExceptions()
selectFromSubQuery()
selectNoExecuteFromSubQuery()
insert()
multiInsert()
update()
updateTimestamp()
updateSingle()
updateNull()
multiUpdate()
delete()
lastAutoID()
formatFields()
delimit()
formatTables()
whereStmt()
formatConditions()
formatConditionsOneField()
formatTimestamp()
tidyInput()
tidyInputNoTrim()
tidyInputClause()
escapeString()
escapeLikeString()
writeCache()
readCache()
deleteCache()
prependTableToField()
dateDiffRatio()
monthDiff()
firstDayOfCurrentYear()
firstDayOfCurrentMonth()
round()
avg()
dateIntervalCondition()
concat()
groupConcat()
caseWhen()
ifClause()
innerJoin()
innerJoinSubQuery()
innerJoinGeneric()
leftJoin()
leftJoinSubQuery()
leftJoinCondition()
leftJoinGeneric()
orderBy()
orderByRandom()
orderByCollate()
groupBy()
limit()
replace()
coalesce()
upper()
regexp()
like()
count()
indexHint()
inClause()
existsClause()
sum()
countAlpha()
printSQLDebug()
$error
$errno
$conditionSeparator
$multiConditionSeparator
$ascDesc
$or
$and
$asc
$desc
$equal
$notEqual
$greater
$less
$greaterEqual
$lessEqual
$plus
$minus
$alias
$from
$condition
$join
$order
$group
$limit
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Properties

$error

$error : 

string

Type

$errno

$errno : 

integer

Type

$conditionSeparator

$conditionSeparator : 

string

Type

$multiConditionSeparator

$multiConditionSeparator : 

string

Type

$ascDesc

$ascDesc : 

string

Type

$or

$or : 

string

Type

$and

$and : 

string

Type

$asc

$asc : 

string

Type

$desc

$desc : 

string

Type

$equal

$equal : 

string

Type

$notEqual

$notEqual : 

string

Type

$greater

$greater : 

string

Type

$less

$less : 

string

Type

$greaterEqual

$greaterEqual : 

string

Type

$lessEqual

$lessEqual : 

string

Type

$plus

$plus : 

string

Type

$minus

$minus : 

string

Type

$alias

$alias : 

string

Type

$from

$from : 

string

Type

$condition

$condition : 

array

Type

$join

$join : 

array

Type

$order

$order : 

array

Type

$group

$group : 

string

Type

$limit

$limit : 

string

Type

Methods

__construct()

__construct() : 

SQL

Returns

getNumberEngineVersion()

getNumberEngineVersion() : 

Get database engine version as number

Returns

getStringEngineVersion()

getStringEngineVersion() : 

Get database engine version as string

Returns

close()

close() : 

Close SQL database

Returns

EnableFullGroupBySqlMode()

EnableFullGroupBySqlMode() : 

Enable full group by only SQL mode of MySQL engine

Returns

DisableFullGroupBySqlMode()

DisableFullGroupBySqlMode() : 

Enable traditional SQL mode of MySQL engine

Returns

enableSqlMode()

enableSqlMode(  SqlMode) : 

Add / enable an SQL mode of MySQL engine

Parameters

SqlMode

Returns

disableSqlMode()

disableSqlMode(  SqlMode) : 

Remove / disable an SQL mode of MySQL engine

Parameters

SqlMode

Returns

setSqlMode()

setSqlMode(  SqlMode) : 

Set an SQL mode of MySQL engine

Parameters

SqlMode

Returns

getMaxPacket()

getMaxPacket() : 

Fetch MySQL server max_allowed_packet variable

Returns

queryNoExecute()

queryNoExecute(  querystring,   saveSession = FALSE) : 

create the entire querystring but do not execute

Parameters

querystring
saveSession

Default is FALSE

Returns

query()

query(  querystring,   saveSession = FALSE) : 

execute queries and return recordset

Parameters

querystring
saveSession

Default is FALSE

Returns

An array, or a boolean if there are no data to return. Only the first result set is returned

queryNoError()

queryNoError( querystring) : 

Execute queries and return recordset

Ignore error warnings

Parameters

querystring

Returns

An array, or a boolean if there are no data to return. Only the first result set is returned

queryNoResult()

queryNoResult(  querystring,   saveSession = FALSE) : 

Execute queries and return TRUE for success, FALSE if the query failed

Parameters

querystring
saveSession

Default is FALSE

Returns

queryFetchFirstRow()

queryFetchFirstRow(  querystring,   saveSession = FALSE) : mixed||string|int

Execute queries, fetch only the first row of the result and return it

Parameters

querystring
saveSession

Default is FALSE

Returns

mixed||string|int —

queryFetchFirstField()

queryFetchFirstField(  querystring,   saveSession = FALSE) : 

Execute queries, fetch only the first field of the first row of the result and return it

Parameters

querystring
saveSession

Default is FALSE

Returns

resetSubs()

resetSubs() : 

reset various strings and arrays used in subclauses

Returns

listFields()

listFields(  table) : mixed||string|int

List fields in a database table

Parameters

table

Returns

mixed||string|int —

listTables()

listTables(  withPrefix = TRUE) : mixed||string|int

show all tables in db

Parameters

withPrefix

Keep the prefix of tables. Default is TRUE.

Returns

mixed||string|int —

tableExists()

tableExists(  table) : mixed||string|int

Check if a table exists in the current database

Parameters

table

Returns

mixed||string|int —

tableIsEmpty()

tableIsEmpty(  table) : 

Is a table Empty?

Parameters

table

Returns

createTable()

createTable(  newTable, mixed||string|int  fieldsArray,   tempTable = FALSE) : 

Create a table

Parameters

newTable
mixed||string|int fieldsArray
tempTable

Returns

numRows()

numRows(mixed||string|int  recordset) : 

return numRows from recordset

Parameters

mixed||string|int recordset

Returns

goToRow()

goToRow(mixed||string|int  recordset,   rowNumber) : 

Adjusts the result pointer to an arbitrary row in the resultset

Parameters

mixed||string|int recordset
rowNumber

Returns

fetchRow()

fetchRow(mixed||string|int  recordset) : mixed||string|int

Fetch one row from the database

Parameters

mixed||string|int recordset

Returns

mixed||string|int —

fetchOne()

fetchOne(mixed||string|int  recordset) : 

Fetch one field value from the database

Parameters

mixed||string|int recordset

Returns

getFieldsProperties()

getFieldsProperties(  table) : mixed||string|int

Fetch fields properties of a recordset

Parameters

table

Name of a table (without prefix)

Returns

mixed||string|int —

union()

union(  stmt,   all = FALSE) : 

Create a UNION sub query -- MySQL 4.1 and above.

Parameters

stmt

string or array select statement(s) to be unionized

all

Default FALSE. Set to TRUE to have 'UNION ALL'

Returns

subQuery()

subQuery(  stmt,   alias = FALSE,   from = TRUE,   clause = FALSE) : 

Create a subquery from a SQL statement

Parameters

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

Returns

subQueryFields()

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 '

Parameters

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

Returns

select()

select(mixed||string|int  tables,   fields,   distinct = FALSE,   tidyFields = TRUE,   alias = FALSE,   clause = FALSE) : 

Execute SELECT statement

Parameters

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

Returns

recordset

selectFirstRow()

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

Parameters

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

Returns

mixed||string|int —

selectFirstField()

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

Parameters

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

Returns

selectNoExecute()

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"

Parameters

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

Returns

selectMax()

selectMax(  table,   maxField,   alias = FALSE, mixed||string|int  otherFields = FALSE,   subQuery = FALSE) : 

Execute SELECT MAX() statement

Parameters

table
maxField
alias

Default is FALSE

mixed||string|int otherFields

Other fields to add to the query. Default is FALSE

subQuery

Default is FALSE

Returns

recordset

selectMin()

selectMin(  table,   minField) : 

Execute a SELECT MIN() statement

Parameters

table
minField

Returns

recordset

selectAverageDate()

selectAverageDate(  table,   field) : 

Execute a "SELECT FROM_UNIXTIME(AVG(UNIX_TIMESTAMP($field))) AS $field FROM $table" statement

Parameters

table
field

Returns

recordset

selectCount()

selectCount(  table,   field) : 

Execute a "SELECT COUNT(*) AS count, $field FROM $table" statement

NB 'count' field in recordset

Parameters

table
field

Returns

recordset

selectCountMax()

selectCountMax(  table,   field) : 

Execute a "SELECT COUNT(*) AS count, $field FROM $table" statement

NB 'count' field in recordset. MAX is achieved by grouping and ordering on $field

Parameters

table
field

Returns

recordset

selectCounts()

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

Parameters

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

Returns

recordset

selectCountsNoExecute()

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

Parameters

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

Returns

selectCountDistinctField()

selectCountDistinctField(  table,   field,   subQuery = FALSE,   clause = FALSE) : 

Execute a "SELECT COUNT(DISTINCT $field) AS count $table $subQuery" statement

NB 'count' field in the recordset

Parameters

table
field
subQuery

Default is FALSE

clause

Default is FALSE

Returns

recordset

selectCountDistinctFieldNoExecute()

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

Parameters

table
field
subQuery

Default is FALSE

clause

Default is FALSE

Returns

selectCountFromSubquery()

selectCountFromSubquery(  field,   subQuery,   clause = FALSE) : 

Execute a "SELECT COUNT(DISTINCT $field) AS count $subQuery" statement

Parameters

field
subQuery
clause

Default is FALSE

Returns

recordset

selectCountFromSubqueryNoExecute()

selectCountFromSubqueryNoExecute(  field,   subQuery,   clause = FALSE) : 

Create a "SELECT COUNT(DISTINCT $field) AS count $subQuery $clause" statment without executing

Parameters

field
subQuery
clause

Default is FALSE

Returns

selectWithExceptions()

selectWithExceptions(mixed||string|int  tables,   fields,   distinct = FALSE) : 

Execute a SELECT statement

Parameters

mixed||string|int tables
fields

Array of fields or '*'

distinct

Default is FALSE

Returns

recordset

selectNoExecuteWithExceptions()

selectNoExecuteWithExceptions(mixed||string|int  tables,   fields,   distinct = FALSE) : 

Create a SELECT statement without executing

Parameters

mixed||string|int tables
fields

Array of fields or '*'

distinct

Default is FALSE

Returns

selectFromSubQuery()

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"

Parameters

mixed||string|int tables
fields

Array of fields or '*'

subQuery
distinct

Default is FALSE

tidy

Format fields. Default is TRUE

clause

Default is FALSE

Returns

recordset

selectNoExecuteFromSubQuery()

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"

Parameters

mixed||string|int tables
fields

Array of fields or '*'

subQuery
distinct

Default is FALSE

tidy

Format fields. Default is TRUE

clause

Default is FALSE

Returns

recordset

insert()

insert(  table, mixed||string|int  fields, mixed||string|int  values) : 

Execute an INSERT statement

Parameters

table
mixed||string|int fields
mixed||string|int values

– can be multi-dimensional array

Returns

multiInsert()

multiInsert(  table, mixed||string|int  fields,   values) : 

Execute an multiple INSERT statement

Parameters

table
mixed||string|int fields
values

Must be formatted as "('1', '2', '3' ...), ('4', '5', '6' ...)"

Returns

update()

update(  table, mixed||string|int  updateArray,   failOnError = TRUE) : 

Execute an UPDATE statement for an array of fields

Parameters

table
mixed||string|int updateArray
failOnError

Optional abort script on error (default TRUE)

Returns

updateTimestamp()

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

Parameters

table
mixed||string|int updateArray

Returns

updateSingle()

updateSingle(  table,   set) : 

Execute an UPDATE statement for a single field

Parameters

table
set

Set statement

Returns

updateNull()

updateNull(  table, mixed||string|int  nulls) : 

Execute an UPDATE statement setting the fields to NULL

Parameters

table
mixed||string|int nulls

Array of fields to set to NULL

Returns

multiUpdate()

multiUpdate(  table,   setField,   conditionField, mixed||string|int  updateArray, mixed||string|int  extraConditions = FALSE) : 

Create and execute a multiple update on one table

Parameters

table
setField
conditionField
mixed||string|int updateArray
mixed||string|int extraConditions

Optional array of formatted conditions joined with an AND to the IN clause

Returns

delete()

delete(  table) : 

Execute a DELETE statement

NB Unless you want to delete all rows from a table, set the condition first!

Parameters

table

Returns

lastAutoID()

lastAutoID() : 

Return last auto_increment ID

Returns

formatFields()

formatFields(mixed||string|int  fields,   withExceptions = FALSE,   tidyLeft = TRUE) : 

Format fields for database type

Parameters

mixed||string|int fields
withExceptions

Default is FALSE

tidyLeft

Default is FALSE

Returns

delimit()

delimit(  stmt,   delimiter) : 

Add delimiters to statements

Parameters

stmt
delimiter

'backtick', 'singleQuote', 'doubleQuote', 'parentheses' (based on MySQL)

Returns

delimited statement

formatTables()

formatTables(  tables,   brackets = FALSE) : 

Format tables for database type

Parameters

tables

Array of tables or single table

brackets

Default is FALSE

Returns

whereStmt()

whereStmt(  conditions,   join) : 

Create a WHERE() statement

Parameters

conditions
join

Default is ''

Returns

formatConditions()

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.

Parameters

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

Returns

Optional return

formatConditionsOneField()

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).

Parameters

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

Returns

formatTimestamp()

formatTimestamp(  time = FALSE) : 

Format a timestamp value as "Y-m-d H:i:s"

Parameters

time

UNIX epoch time. Default is FALSE (in which case time() is used)

Returns

tidyInput()

tidyInput(  string) : 

Format field values for database type

Fields are trimmed

Parameters

string

Returns

tidyInputNoTrim()

tidyInputNoTrim(  string) : 

Format field values for database type

Fields are not trimmed

Parameters

string

Returns

tidyInputClause()

tidyInputClause(  string) : 

Format field values for database type

For use with ORDER or GROUP by clauses

Parameters

string

Returns

escapeString()

escapeString(  string) : 

Escape a string according to db type

Parameters

string

Returns

escapeLikeString()

escapeLikeString(  string) : 

Escape a string for the LIKE statement according to db type

Parameters

string

Returns

writeCache()

writeCache(  field, mixed||string|int  array) : 

Write a WIKINDX database cache

Parameters

field
mixed||string|int array

Returns

readCache()

readCache(  field) : mixed||string|int

Read a WIKINDX database cache

Parameters

field

Returns

mixed||string|int —

deleteCache()

deleteCache(  field) : 

Delete a WIKINDX database cache

Parameters

field

Returns

prependTableToField()

prependTableToField(  table,   fields) : 

prepend the configured table name to the field names

Parameters

table
fields

Array of field names or single field name

Returns

dateDiffRatio()

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.

Parameters

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

Returns

monthDiff()

monthDiff(  date1,   date2 = FALSE) : 

Return number months difference between two database timestamps

Parameters

date1

Timestamp value from database

date2

Default is FALSE. If FALSE, CURRENT_TIMESTAMP is assumed

Returns

firstDayOfCurrentYear()

firstDayOfCurrentYear() : 

Return SQL code to retrieve the first day of the current year

Returns

firstDayOfCurrentMonth()

firstDayOfCurrentMonth() : 

Return SQL code to retrieve the first day of the current mounth

Returns

round()

round(  clause,   alias = FALSE,   round = 3) : 

Create a ROUND() clause

Parameters

clause
alias

Default is FALSE

round

Default is 3

Returns

avg()

avg(  clause) : 

Return a AVG() clause

Parameters

clause

Returns

dateIntervalCondition()

dateIntervalCondition(  limit,   timescale = day,   fromTime = now) : 

Create a condition clause for a time interval: "DATE_SUB($fromTime, INTERVAL $limit $timescale)"

Parameters

limit
timescale

Default is 'day'

fromTime

Default is 'now'

Returns

concat()

concat(mixed||string|int  array,   separator = FALSE) : 

Create a CONCAT clause

Parameters

mixed||string|int array
separator

Default is FALSE. If !FALSE, CONCAT_WS() is used, else CONCAT().

Returns

groupConcat()

groupConcat(  field,   separator = FALSE,   distinct = FALSE) : 

Create a GROUP_CONCAT clause

Parameters

field
separator

Default is FALSE.

distinct

Default is FALSE

Returns

caseWhen()

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;

Parameters

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

Returns

ifClause()

ifClause(  field,   test,   result,   default) : 

Create an IF clause: "IF($field $test, $result, $default)"

Parameters

field
test
result
default

Returns

innerJoin()

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.

Parameters

table
left
right

Default is FALSE

tidy

Default is TRUE. If TRUE, format fields for database type

Returns

innerJoinSubQuery()

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.

Parameters

subQuery
left
right

Default is FALSE

tidy

Default is TRUE. If TRUE, format fields for database type

Returns

innerJoinGeneric()

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.

Parameters

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

Returns

leftJoin()

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.

Parameters

table
left
right

Default is FALSE

tidy

Default is TRUE. If TRUE, format fields for database type

Returns

leftJoinSubQuery()

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.

Parameters

subQuery
left
right

Default is FALSE

tidy

Default is TRUE. If TRUE, format fields for database type

Returns

leftJoinCondition()

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.

Parameters

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

Returns

leftJoinGeneric()

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.

Parameters

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

Returns

orderBy()

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.

Parameters

field
tidy

Default is TRUE. If TRUE, format fields for database type

removeBraces

Default is TRUE. If TRUE, remove {...} braces

Returns

orderByRandom()

orderByRandom() : 

Create an ORDER BY RAND() 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.

Returns

orderByCollate()

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.

Parameters

field
tidy

Default is TRUE. If TRUE, format fields for database type

Returns

groupBy()

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.

Parameters

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.

Returns

limit()

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.

Parameters

limit
offset
return

If TRUE, return the limit statement rather than setting it. Default is FALSE

Returns

replace()

replace(  field,   find,   replace,   tidy = TRUE) : 

Create a REPLACE clause: "REPLACE(' . $field . ", '$find', '$replace')"

Parameters

field
find
replace
tidy

Default is TRUE. If TRUE, format fields for database type

Returns

coalesce()

coalesce(  fields,   alias = FALSE) : 

Create a COALESCE clause: "COALESCE($fields) $alias"

Parameters

fields

Array of field names or single field name

alias

Returns

upper()

upper(  field,   tidy = TRUE) : 

Create an UPPER clause

Parameters

field
tidy

Default is TRUE. If TRUE, format fields for database type

Returns

regexp()

regexp(  first,   test,   last,   not = FALSE) : 

Create a REGEXP clause

Parameters

first
test
last
not

Default is FALSE

Returns

like()

like(  first,   test,   last,   not = FALSE) : 

Create a LIKE clause

Parameters

first
test
last
not

Default is FALSE

Returns

count()

count(  field,   operator = FALSE,   comparison = FALSE,   distinct = FALSE,   alias = FALSE) : 

Create a COUNT() clause

Parameters

field

Database field to count

operator

Optional =, !=, >, <. Default is FALSE

comparison

Comparison following $operator. Default is FALSE

distinct

TRUE/FALSE (default). COUNT(DISTINCT field)

alias

COUNT(field) AS $alias. Default is FALSE

Returns

indexHint()

indexHint(  field,   type = FORCE) : 

Clause for using an index in a SQL query

Parameters

field
type

Default is 'FORCE'

Returns

inClause()

inClause(  stmt,   not = FALSE) : 

Create an IN() clause

Parameters

stmt

IN ($stmt)

not

Default is FALSE

Returns

existsClause()

existsClause(  stmt,   not = FALSE) : 

Create an EXISTS() clause

Parameters

stmt

IN ($stmt)

not

Default is FALSE

Returns

sum()

sum(  field,   alias = FALSE) : 

Create a SUM() statement

Parameters

field
alias

Default is FALSE

Returns

countAlpha()

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

Parameters

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'

Returns

printSQLDebug()

printSQLDebug(  querystring,   executionType = SQL) : 

Format display of SQL query in debug mode

Parameters

querystring

SQL of a query to display

executionType

Description of execution type (EXEC, NOEXEC...)

Returns