Exponent v2.7.2

database
in package

This is the abstract class database

This is the generic implementation of the database class.

Tags
subpackage

Database

Table of Contents

$connection  : string
$havedb  : bool
$prefix  : string
__construct()  : mixed
Make a connection to the Database Server
adjustNestedTreeBetween()  : void
adjustNestedTreeFrom()  : void
alterTable()  : array<string|int, mixed>
Alter an existing table
columnExists()  : bool
Check to see if the named column within a table exists in the database.
columnUpdate()  : void
Update a column in all records in a table
complex_pdo()  : mixed
The difference between this method and the `simple` one, is that you can apply additional `where` conditions to the SQL queries. These can be in one of two forms:
countObjects()  : int
Count Objects matching a given criteria
countObjectsBySql()  : int
Count Objects matching a given criteria using raw sql
createTable()  : array<string|int, mixed>
Create a new Table
currencyStmt()  : string
Return the number to currency statement for the database
databaseInfo()  : array<string|int, mixed>
Returns table information for all tables in the database.
datetimeStmt()  : string
Return the unixtime to date statement for the database
decrement()  : mixed
Decrement a numeric table field in a table.
delete()  : mixed
Delete one or more objects from the given table.
deleteNestedNode()  : void
describeTable()  : mixed
dropTable()  : bool
Drop a table from the database
error()  : string
Returns an error message from the database server. This is intended to be used by the implementers of the database wrapper, so that certain cryptic error messages can be reworded.
escapeString()  : string
Escape a string based on the database connection
filter_pdo()  : mixed
Searching / Filtering
getDataDefinition()  : array<string|int, mixed>|null
Build a data definition from a pre-existing table. This is used to intelligently alter tables that have already been installed.
getTables()  : array<string|int, mixed>
Get a list of all tables in the database. Optionally, only the tables in the current logical database (tables with the same prefix) can be retrieved.
getTextColumns()  : array<string|int, mixed>
This function returns all the text columns in the given table
increment()  : mixed
Increment a numeric table field in a table.
inError()  : bool
Checks whether the database connection has experienced an error.
injectProof()  : string
Attempt to prevent a sql injection
insertObject()  : int|void
Insert an Object into some table in the Database
isValid()  : bool
Checks to see if the connection for this database object is valid.
limit()  : string
Create a SQL "limit" phrase
limit_pdo()  : mixed
Paging
limitStmt()  : string
Return the limit statement for the database
lockTable()  : mixed
max()  : mixed
Find the maximum value of a field. This is similar to a standard SELECT MAX(field) ... query.
optimize()  : bool
Runs whatever table optimization routines the database engine supports.
order_pdo()  : mixed
Ordering
queryRows()  : int|void
Count Objects matching a given criteria using raw sql
selectAndJoinObjects()  : mixed
selectArray()  : array<string|int, mixed>|void
Select a record from the database as an array Selects a set of arrays from the database. Because of the way Exponent handles objects and database tables, this is akin to SELECTing a set of records from a database table. Returns an array of arrays, in any random order.
selectArrays()  : array<string|int, mixed>
Select an array of arrays
selectArraysBySql()  : array<string|int, mixed>
Select an array of arrays
selectColumn()  : array<string|int, mixed>
selectDropdown()  : array<string|int, mixed>
selectExpObjects()  : array<string|int, mixed>
Instantiate objects from selected records from the database
selectExpObjectsBySql()  : mixed
Instantiate objects from selected records from the database
selectFormattedNestedTree()  : mixed
selectNestedBranch()  : array<string|int, mixed>
selectNestedNodeChildren()  : array<string|int, mixed>
selectNestedNodeParent()  : array<string|int, mixed>
selectNestedTree()  : array<string|int, mixed>
selectObject()  : object|null|void
Select a single object.
selectObjectBySql()  : null|void
Select a single object by sql
selectObjects()  : array<string|int, mixed>
Select a series of objects
selectObjectsBySql()  : array<string|int, mixed>
Select a series of objects by sql
selectObjectsInArray()  : array<string|int, mixed>
This function takes an array of indexes and returns an array with the objects associated with each id
selectObjectsIndexedArray()  : array<string|int, mixed>
Select a series of objects, and return by ID
selectPathToNestedNode()  : array<string|int, mixed>
selectSearch()  : array<string|int, mixed>
selectSum()  : mixed
selectValue()  : null
selectValueBySql()  : null
setUniqueFlag()  : bool
simple_pdo()  : mixed
Perform the SQL queries needed for an server-side processing requested, utilising the helper functions of this class, limit(), order() and filter() among others. The returned array is ready to be encoded as JSON in response to an SSP request, or can be modified if needed before sending back to the client.
sql()  : mixed
Run raw SQL. Returns true if the query succeeded, and false if an error was returned from the database server.
sql_connect_pdo()  : PDO
Connect to the database by PDO
switchValues()  : bool
Switch field values between two entries in a Table
tableExists()  : bool
Check to see if the named table exists in the database.
tableInfo()  : null
Retrieve table information for a named table.
tableIsEmpty()  : bool
Check whether or not a table in the database is empty (0 rows).
tableStmt()  : string
Return the tablename for the database
testPrivileges()  : array<string|int, mixed>
Test the privileges of the user account for the connection.
toggle()  : void
Toggle a boolean value in a Table Entry
trim_revisions()  : mixed
Reduces table item revisions to a passed total
unlockTables()  : mixed
updateObject()  : bool|int|void
Update one or more objects in the database.
wrapStmt()  : string
Return a sql statement with keywords wrapped for the database

Properties

$connection

public string $connection = \null

Database connection string

Methods

__construct()

Make a connection to the Database Server

public abstract __construct(string $username, string $password, string $hostname, string $database[, bool $new = false ]) : mixed

Takes the supplied credentials (username / password) and tries to connect to the server and select the given database. All the rules governing database connect also govern this method.

Parameters
$username : string

The username to connect to the server as.

$password : string

The password for $username

$hostname : string

The hostname of the database server. If localhost is specified, a local socket connection will be attempted.

$database : string

The name of the database to use. Multi-database sites are still not yet supported.

$new : bool = false

Whether or not to force the PHP connection function to establish a distinctly new connection handle to the server.

Return values
mixed

adjustNestedTreeBetween()

public adjustNestedTreeBetween( $table,  $lft,  $rgt,  $width) : void
Parameters
$table :
$lft :
$rgt :
$width :
Return values
void

adjustNestedTreeFrom()

public adjustNestedTreeFrom( $table,  $start,  $width) : void
Parameters
$table :
$start :
$width :
Return values
void

alterTable()

Alter an existing table

public abstract alterTable(string $tablename, array<string|int, mixed> $newdatadef, array<string|int, mixed> $info[, bool $aggressive = false ]) : array<string|int, mixed>

Alters the structure of an existing database table to conform to the passed data definition.

This function abides by the Exponent Data Definition Language, and interprets its general structure for databases.

Parameters
$tablename : string

The name of the table to alter

$newdatadef : array<string|int, mixed>

The new data definition for the table. This is expressed in the Exponent Data Definition Language

$info : array<string|int, mixed>

Information about the table itself.

$aggressive : bool = false

Whether or not to aggressively update the table definition. An aggressive update will drop columns in the table that are not in the Exponent definition.

Return values
array<string|int, mixed>

columnExists()

Check to see if the named column within a table exists in the database.

public abstract columnExists(string $table, string $col) : bool

Returns true if the column exists, and false if it doesn't.

Parameters
$table : string

Name of the table to look in.

$col : string

Name of the column to look for.

Return values
bool

columnUpdate()

Update a column in all records in a table

public abstract columnUpdate( $table,  $col,  $val[, int|null $where = 1 ]) : void
Parameters
$table :
$col :
$val :
$where : int|null = 1
Return values
void

complex_pdo()

The difference between this method and the `simple` one, is that you can apply additional `where` conditions to the SQL queries. These can be in one of two forms:

public static complex_pdo(array<string|int, mixed> $request, mixed $table, mixed $primaryKey, mixed $columns[, mixed $whereResult = null ][, mixed $whereAll = null ]) : mixed
  • 'Result condition' - This is applied to the result set, but not the overall paging information query - i.e. it will not effect the number of records that a user sees they can have access to. This should be used when you want apply a filtering condition that the user has sent.
  • 'All condition' - This is applied to all queries that are made and reduces the number of records that the user can access. This should be used in conditions where you don't want the user to ever have access to particular records (for example, restricting by a login id).
Parameters
$request : array<string|int, mixed>

Data sent to server by DataTables @param string $table SQL table to query @param string $primaryKey Primary key of the table @param array $columns Column information array @param string $whereResult WHERE condition to apply to the result set @param string $whereAll WHERE condition to apply to all queries

@return array Server-side processing response array

$table : mixed
$primaryKey : mixed
$columns : mixed
$whereResult : mixed = null
$whereAll : mixed = null
Return values
mixed

countObjects()

Count Objects matching a given criteria

public abstract countObjects(string $table[, string $where = null ][, bool $is_revisioned = false ][, bool $needs_approval = false ][, null $user = null ]) : int
Parameters
$table : string

The name of the table to count objects in.

$where : string = null

Criteria for counting.

$is_revisioned : bool = false
$needs_approval : bool = false
$user : null = null
Return values
int

countObjectsBySql()

Count Objects matching a given criteria using raw sql

public abstract countObjectsBySql(string $sql) : int
Parameters
$sql : string

The sql query to be run

Return values
int

createTable()

Create a new Table

public abstract createTable(string $tablename, array<string|int, mixed> $datadef, array<string|int, mixed> $info) : array<string|int, mixed>

Creates a new database table, according to the passed data definition.

This function abides by the Exponent Data Definition Language, and interprets its general structure for databases.

Parameters
$tablename : string

The name of the table to create

$datadef : array<string|int, mixed>

The data definition to create, expressed in the Exponent Data Definition Language.

$info : array<string|int, mixed>

Information about the table itself.

Return values
array<string|int, mixed>

currencyStmt()

Return the number to currency statement for the database

public abstract currencyStmt(string $column_name) : string

Returns a correct number to currency statement for the database.

Parameters
$column_name : string

The name of the data column to convert

Return values
string

databaseInfo()

Returns table information for all tables in the database.

public abstract databaseInfo() : array<string|int, mixed>

This function effectively calls tableInfo() on each table found.

Return values
array<string|int, mixed>

datetimeStmt()

Return the unixtime to date statement for the database

public abstract datetimeStmt(string $column_name) : string

Returns a correct unixtime to date statement for the database.

Parameters
$column_name : string

The name of the data column to convert

Return values
string

decrement()

Decrement a numeric table field in a table.

public decrement(string $table, string $field, int $step[, string $where = null ]) : mixed
Parameters
$table : string

The name of the table to decrement in.

$field : string

The field to decrement.

$step : int

The step value. Usually 1. This can be negative, to increment, but the increment() method is preferred, for readability.

$where : string = null

Optional criteria to determine which records to update.

Return values
mixed

delete()

Delete one or more objects from the given table.

public abstract delete(string $table[, string $where = null ]) : mixed
Parameters
$table : string

The name of the table to delete from.

$where : string = null

Criteria for determining which record(s) to delete.

Return values
mixed

deleteNestedNode()

public deleteNestedNode( $table,  $lft,  $rgt) : void
Parameters
$table :
$lft :
$rgt :
Return values
void

describeTable()

public describeTable( $table) : mixed
Parameters
$table :
Return values
mixed

dropTable()

Drop a table from the database

public abstract dropTable(string $table) : bool

Removes an existing table from the database. Returns true if the table was dropped, false if there was an error returned by the database server.

Parameters
$table : string

The name of the table to drop.

Return values
bool

error()

Returns an error message from the database server. This is intended to be used by the implementers of the database wrapper, so that certain cryptic error messages can be reworded.

public abstract error() : string
Return values
string

escapeString()

Escape a string based on the database connection

public abstract escapeString( $string) : string
Parameters
$string :
Return values
string

filter_pdo()

Searching / Filtering

public static filter_pdo(array<string|int, mixed> $request, mixed $columns, mixed &$bindings) : mixed

Construct the WHERE clause for server-side processing SQL query.

NOTE this does not match the built-in DataTables filtering which does it word by word on any field. It's possible to do here performance on large databases would be very poor

Parameters
$request : array<string|int, mixed>

Data sent to server by DataTables @param array $columns Column information array @param array $bindings Array of values for PDO bindings, used in the sql_exec() function @return string SQL where clause

$columns : mixed
$bindings : mixed
Return values
mixed

getDataDefinition()

Build a data definition from a pre-existing table. This is used to intelligently alter tables that have already been installed.

public abstract getDataDefinition(string $table) : array<string|int, mixed>|null
Parameters
$table : string

The name of the table to get a data definition for.

Return values
array<string|int, mixed>|null

getTables()

Get a list of all tables in the database. Optionally, only the tables in the current logical database (tables with the same prefix) can be retrieved.

public abstract getTables([bool $prefixed_only = true ]) : array<string|int, mixed>
Parameters
$prefixed_only : bool = true

Whether to return only the tables for the logical database, or all tables in the physical database.

Return values
array<string|int, mixed>

getTextColumns()

This function returns all the text columns in the given table

public abstract getTextColumns( $table) : array<string|int, mixed>
Parameters
$table :
Return values
array<string|int, mixed>

increment()

Increment a numeric table field in a table.

public abstract increment(string $table, string $field, int $step[, string $where = null ]) : mixed
Parameters
$table : string

The name of the table to increment in.

$field : string

The field to increment.

$step : int

The step value. Usually 1. This can be negative, to decrement, but the decrement() method is preferred, for readability.

$where : string = null

Optional criteria to determine which records to update.

Return values
mixed

inError()

Checks whether the database connection has experienced an error.

public abstract inError() : bool
Return values
bool

injectProof()

Attempt to prevent a sql injection

public injectProof( $string) : string
Parameters
$string :
Return values
string

insertObject()

Insert an Object into some table in the Database

public abstract insertObject(object $object, string $table) : int|void

This method will return the ID assigned to the new record by database. Note that object attributes starting with an underscore ('_') will be ignored and NOT inserted into the table as a field value.

Parameters
$object : object

The object to insert.

$table : string

The logical table name to insert into. This does not include the table prefix, which is automagically prepended for you.

Return values
int|void

isValid()

Checks to see if the connection for this database object is valid.

public isValid() : bool
Return values
bool

True if the connection can be used to execute SQL queries.

limit()

Create a SQL "limit" phrase

public limit( $num,  $offset) : string
Parameters
$num :
$offset :
Return values
string

limit_pdo()

Paging

public static limit_pdo(array<string|int, mixed> $request) : mixed

Construct the LIMIT clause for server-side processing SQL query

Parameters
$request : array<string|int, mixed>

Data sent to server by DataTables @return string SQL limit clause

Return values
mixed

limitStmt()

Return the limit statement for the database

public abstract limitStmt(int $count, int $offset) : string

Returns a correct limit statement for the database.

Parameters
$count : int

The number of records to return

$offset : int

The offset to the first record to return

Return values
string

lockTable()

public abstract lockTable( $table[, string $lockType = "WRITE" ]) : mixed
Parameters
$table :
$lockType : string = "WRITE"
Return values
mixed

max()

Find the maximum value of a field. This is similar to a standard SELECT MAX(field) ... query.

public abstract max(string $table, string $attribute[, string $groupfields = null ][, string $where = null ]) : mixed
Parameters
$table : string

The name of the table to select from.

$attribute : string

The attribute name to find a maximum value for.

$groupfields : string = null

A comma-separated list of fields (or a single field) name, used for a GROUP BY clause. This can also be passed as an array of fields.

$where : string = null

Optional criteria for narrowing the result set.

Return values
mixed

optimize()

Runs whatever table optimization routines the database engine supports.

public abstract optimize(string $table) : bool
Parameters
$table : string

The name of the table to optimize.

Return values
bool

order_pdo()

Ordering

public static order_pdo(array<string|int, mixed> $request, mixed $columns) : mixed

Construct the ORDER BY clause for server-side processing SQL query

Parameters
$request : array<string|int, mixed>

Data sent to server by DataTables @param array $columns Column information array @return string SQL order by clause

$columns : mixed
Return values
mixed

queryRows()

Count Objects matching a given criteria using raw sql

public queryRows(string $sql) : int|void
Parameters
$sql : string

The sql query to be run

Return values
int|void

selectAndJoinObjects()

public selectAndJoinObjects([null $colsA = null ][, null $colsB = null ][,  $tableA = null ][,  $tableB = null ][,  $keyA = null ][, null $keyB = null ][, null $where = null ][, null $orderby = null ]) : mixed
Parameters
$colsA : null = null
$colsB : null = null
$tableA : = null
$tableB : = null
$keyA : = null
$keyB : null = null
$where : null = null
$orderby : null = null
Return values
mixed

selectArray()

Select a record from the database as an array Selects a set of arrays from the database. Because of the way Exponent handles objects and database tables, this is akin to SELECTing a set of records from a database table. Returns an array of arrays, in any random order.

public abstract selectArray(string $table[, string $where = null ][, null $orderby = null ][, bool $is_revisioned = false ][, bool $needs_approval = false ][, null $user = null ]) : array<string|int, mixed>|void
Parameters
$table : string

The name of the table/object to look at

$where : string = null

Criteria used to narrow the result set. If this is specified as null, then no criteria is applied, and all objects are returned

$orderby : null = null
$is_revisioned : bool = false
$needs_approval : bool = false
$user : null = null
Return values
array<string|int, mixed>|void

selectArrays()

Select an array of arrays

public abstract selectArrays(string $table[, string $where = null ][, string $orderby = null ][, bool $is_revisioned = false ][, bool $needs_approval = false ][, null $user = null ]) : array<string|int, mixed>

Selects a set of arrays from the database. Because of the way Exponent handles objects and database tables, this is akin to SELECTing a set of records from a database table. Returns an array of arrays, in any random order.

Parameters
$table : string

The name of the table/object to look at

$where : string = null

Criteria used to narrow the result set. If this is specified as null, then no criteria is applied, and all objects are returned

$orderby : string = null
$is_revisioned : bool = false
$needs_approval : bool = false
$user : null = null
Return values
array<string|int, mixed>

selectArraysBySql()

Select an array of arrays

public abstract selectArraysBySql(string $sql) : array<string|int, mixed>

Selects a set of arrays from the database. Because of the way Exponent handles objects and database tables, this is akin to SELECTing a set of records from a database table. Returns an array of arrays, in any random order.

Parameters
$sql : string

The name of the table/object to look at

Return values
array<string|int, mixed>

selectColumn()

public abstract selectColumn( $table,  $col[, null $where = null ][, null $orderby = null ][, bool $distinct = false ]) : array<string|int, mixed>
Parameters
$table :
$col :
$where : null = null
$orderby : null = null
$distinct : bool = false
Return values
array<string|int, mixed>

selectDropdown()

public abstract selectDropdown( $table,  $col[, null $where = null ][, null $orderby = null ]) : array<string|int, mixed>
Parameters
$table :
$col :
$where : null = null
$orderby : null = null
Return values
array<string|int, mixed>

selectExpObjects()

Instantiate objects from selected records from the database

public abstract selectExpObjects([string $table = null ][, string $where = null ][,  $classname = null ][, bool $get_assoc = true ][, bool $get_attached = true ][, array<string|int, mixed> $except = array() ][, bool $cascade_except = false ][, null $order = null ][, null $limitsql = null ][, bool $is_revisioned = false ][, bool $needs_approval = false ][, null $user = null ]) : array<string|int, mixed>
Parameters
$table : string = null

The name of the table/object to look at

$where : string = null

Criteria used to narrow the result set. If this is specified as null, then no criteria is applied, and all objects are returned

$classname : = null
$get_assoc : bool = true
$get_attached : bool = true
$except : array<string|int, mixed> = array()
$cascade_except : bool = false
$order : null = null
$limitsql : null = null
$is_revisioned : bool = false
$needs_approval : bool = false
$user : null = null
Return values
array<string|int, mixed>

selectExpObjectsBySql()

Instantiate objects from selected records from the database

public selectExpObjectsBySql(string $sql, string $classname[, bool $get_assoc = true ][, bool $get_attached = true ]) : mixed
Parameters
$sql : string

The sql statement to run on the model/classname

$classname : string

Can be $this->baseclassname Returns an array of fields

$get_assoc : bool = true
$get_attached : bool = true
Return values
mixed

selectFormattedNestedTree()

public selectFormattedNestedTree(mixed $table) : mixed
Parameters
$table : mixed
Return values
mixed

selectNestedBranch()

public selectNestedBranch( $table[, null $node = null ]) : array<string|int, mixed>
Parameters
$table :
$node : null = null
Return values
array<string|int, mixed>

selectNestedNodeChildren()

public selectNestedNodeChildren( $table[, null $node = null ]) : array<string|int, mixed>
Parameters
$table :
$node : null = null
Return values
array<string|int, mixed>

selectNestedNodeParent()

public selectNestedNodeParent( $table[, null $node = null ]) : array<string|int, mixed>
Parameters
$table :
$node : null = null
Return values
array<string|int, mixed>

selectNestedTree()

public selectNestedTree( $table) : array<string|int, mixed>
Parameters
$table :
Return values
array<string|int, mixed>

selectObject()

Select a single object.

public abstract selectObject(string $table, string $where) : object|null|void

Selects an objects from the database. Because of the way Exponent handles objects and database tables, this is akin to SELECTing a single record from a database table. Returns the first record/object found (in the case of multiple-result queries, there is no way to determine which of the set will be returned). If no record(s) match the query, null is returned.

Parameters
$table : string

The name of the table/object to look at

$where : string

Criteria used to narrow the result set.

Return values
object|null|void

selectObjectBySql()

Select a single object by sql

public abstract selectObjectBySql( $sql) : null|void
Parameters
$sql :
Return values
null|void

selectObjects()

Select a series of objects

public abstract selectObjects(string $table[, string $where = null ][, null $orderby = null ][, bool $is_revisioned = false ][, bool $needs_approval = false ][, null $user = null ]) : array<string|int, mixed>

Selects a set of objects from the database. Because of the way Exponent handles objects and database tables, this is akin to SELECTing a set of records from a database table. Returns an array of objects, in any random order.

Parameters
$table : string

The name of the table/object to look at

$where : string = null

Criteria used to narrow the result set. If this is specified as null, then no criteria is applied, and all objects are returned

$orderby : null = null
$is_revisioned : bool = false
$needs_approval : bool = false
$user : null = null
Return values
array<string|int, mixed>

selectObjectsBySql()

Select a series of objects by sql

public abstract selectObjectsBySql( $sql) : array<string|int, mixed>
Parameters
$sql :
Return values
array<string|int, mixed>

selectObjectsInArray()

This function takes an array of indexes and returns an array with the objects associated with each id

public selectObjectsInArray( $table[, array<string|int, mixed> $array = array() ][, null $orderby = null ]) : array<string|int, mixed>
Parameters
$table :
$array : array<string|int, mixed> = array()
$orderby : null = null
Return values
array<string|int, mixed>

selectObjectsIndexedArray()

Select a series of objects, and return by ID

public abstract selectObjectsIndexedArray(string $table[, string $where = null ][, null $orderby = null ]) : array<string|int, mixed>

Selects a set of objects from the database. Because of the way Exponent handles objects and database tables, this is akin to SELECTing a set of records from a database table. Returns an array of objects, in any random order. The indices of the array are the IDs of the objects.

Parameters
$table : string

The name of the table/object to look at

$where : string = null

Criteria used to narrow the result set. If this is specified as null, then no criteria is applied, and all objects are returned

$orderby : null = null
Return values
array<string|int, mixed>

selectPathToNestedNode()

public selectPathToNestedNode( $table[, null $node = null ]) : array<string|int, mixed>
Parameters
$table :
$node : null = null
Return values
array<string|int, mixed>

selectSearch()

public abstract selectSearch( $terms[, null $where = null ]) : array<string|int, mixed>
Parameters
$terms :
$where : null = null
Return values
array<string|int, mixed>

selectSum()

public selectSum( $table,  $col[, null $where = null ]) : mixed
Parameters
$table :
$col :
$where : null = null
Return values
mixed

selectValue()

public abstract selectValue( $table,  $col[, null $where = null ]) : null
Parameters
$table :
$col :
$where : null = null
Return values
null

selectValueBySql()

public selectValueBySql( $sql) : null
Parameters
$sql :
Return values
null

setUniqueFlag()

public setUniqueFlag( $object,  $table,  $col[, int|null $where = 1 ]) : bool
Parameters
$object :
$table :
$col :
$where : int|null = 1
Return values
bool

simple_pdo()

Perform the SQL queries needed for an server-side processing requested, utilising the helper functions of this class, limit(), order() and filter() among others. The returned array is ready to be encoded as JSON in response to an SSP request, or can be modified if needed before sending back to the client.

public static simple_pdo(mixed $request, string $table, mixed $primaryKey, mixed $columns) : mixed

@param array $request Data sent to server by DataTables

Parameters
$request : mixed
$table : string

SQL table to query @param string $primaryKey Primary key of the table @param array $columns Column information array @return array Server-side processing response array

$primaryKey : mixed
$columns : mixed
Return values
mixed

sql()

Run raw SQL. Returns true if the query succeeded, and false if an error was returned from the database server.

public abstract sql(string $sql[, bool $escape = true ]) : mixed
If you can help it, do not use this function. It presents Database Portability Issues.

Runs a straight SQL query on the database. This is not a very portable way of dealing with the database, and is only provided as a last resort.

Parameters
$sql : string

The SQL query to run

$escape : bool = true
Return values
mixed

sql_connect_pdo()

Connect to the database by PDO

public abstract sql_connect_pdo() : PDO
Return values
PDO

Database connection handle

switchValues()

Switch field values between two entries in a Table

public switchValues( $table,  $field,  $a,  $b[, null $additional_where = null ]) : bool

Switches values between two table entries for things like swapping rank, etc...

Parameters
$table :
$field :
$a :
$b :
$additional_where : null = null
Return values
bool

tableExists()

Check to see if the named table exists in the database.

public abstract tableExists(string $table) : bool

Returns true if the table exists, and false if it doesn't.

Parameters
$table : string

Name of the table to look for.

Return values
bool

tableInfo()

Retrieve table information for a named table.

public tableInfo( $table) : null

Returns an object, with the following attributes:

  • rows -- The number of rows in the table.
  • average_row_length -- The average storage size of a row in the table.
  • data_total -- How much total disk space is used by the table.
  • data_overhead -- How much storage space in the table is unused (for compacting purposes)
Parameters
$table :
Return values
null

tableIsEmpty()

Check whether or not a table in the database is empty (0 rows).

public tableIsEmpty(string $table) : bool

Returns tue of the specified table has no rows, and false if otherwise.

Parameters
$table : string

Name of the table to check.

Return values
bool

tableStmt()

Return the tablename for the database

public abstract tableStmt(string $tablename) : string

Returns a full table name for the database.

Parameters
$tablename : string

The name of the table

Return values
string

testPrivileges()

Test the privileges of the user account for the connection.

public testPrivileges() : array<string|int, mixed>

Tests run include:

  • CREATE TABLE
  • INSERT
  • SELECT
  • UPDATE
  • DELETE
  • ALTER TABLE
  • DROP TABLE
These tests must be performed in order, for logical reasons. Execution terminates when the first test fails, and the status flag array is returned then. Returns an array of status flags. Key is the test name. Value is a boolean, true if the test succeeded, and false if it failed.
Return values
array<string|int, mixed>

toggle()

Toggle a boolean value in a Table Entry

public toggle( $table,  $col[, null $where = null ]) : void
Parameters
$table :
$col :
$where : null = null
Return values
void

trim_revisions()

Reduces table item revisions to a passed total

public trim_revisions(string $table, int $id, int $num[, int|string $workflow = ENABLE_WORKFLOW ]) : mixed
Parameters
$table : string

The name of the table to trim

$id : int

The item id

$num : int

The number of revisions to retain

$workflow : int|string = ENABLE_WORKFLOW

is workflow turned on (or force)

Return values
mixed

unlockTables()

public abstract unlockTables() : mixed
Return values
mixed

updateObject()

Update one or more objects in the database.

public abstract updateObject(object $object, string $table[, string $where = null ][, string $identifier = 'id' ][, bool $is_revisioned = false ]) : bool|int|void

This function will only update the attributes of the resulting record(s) that are also member attributes of the $object object.

Parameters
$object : object

An object specifying the fields and values for updating. In most cases, this will be the altered object originally returned from one of the select* methods.

$table : string

The table to update in.

$where : string = null

Optional criteria used to narrow the result set.

$identifier : string = 'id'
$is_revisioned : bool = false
Return values
bool|int|void

wrapStmt()

Return a sql statement with keywords wrapped for the database

public abstract wrapStmt(string $sql) : string

Returns a keyword wrapped sql statement for the database.

Parameters
$sql : string

The sql statement to check for keyword wrap

Return values
string

Search results