expDatabase

This is the expDatabase subsystem Handles all database abstraction in Exponent.

package

Subsystems

subpackage

Subsystems

Methods

Return a string from an array or a string

_flatten(array|string $a, string $join = ' AND ') : string
static

Arguments

$a

array|string

Array to join

$join

string

Glue for the concatenation

Response

string

Joined string

List all available database backends

backends(integer $valid_only = 1) : Array
static

This function looks for available database engines, and then returns an array to the caller.

Arguments

$valid_only

integer

Response

Array

An associative array of engine identifiers. The internal engine name is the key, and the external descriptive name is the value.

Create a PDO binding key which can be used for escaping variables safely when executing a query with sql_exec()

bind( &$a, \* $val, integer $type) : string
static

Arguments

$a

$val

\*

Value to bind

$type

integer

PDO field type

Response

string

Bound key to be used in the SQL where this parameter would be used.

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:

complex(array $request,  $table,  $primaryKey,  $columns,  $whereResult = null,  $whereAll = null) 
static
  • '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).

Arguments

$request

array

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

$primaryKey

$columns

$whereResult

$whereAll

Connect to the Exponent database

connect(string $username, string $password, string $hostname, string $database, string $dbclass = '', boolean $new = false, null $log = null) : \database
static

This function attempts to connect to the exponent database, and then returns the database object to the caller.

Arguments

$username

string

the database username

$password

string

the database password

$hostname

string

the url of the database server

$database

string

the name of the database

$dbclass

string

$new

boolean

$log

null

Response

\database

the database object

Create the data output array for the DataTables rows

data_output( $columns, array $data) 
static

@param array $columns Column information array

Arguments

$columns

$data

array

Data from the SQL get @return array Formatted data in a row based format

Throw a fatal error.

fatal(string $msg) 
static

This writes out an error message in a JSON string which DataTables will see and show to the user in the browser.

Arguments

$msg

string

Message to send to the client

Searching / Filtering

filter(array $request,  $columns,  &$bindings) 
static

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

Arguments

$request

array

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

$bindings

fix_table_names

fix_table_names() 
static

install_dbtables

install_dbtables( $aggressive = false,  $workflow = ENABLE_WORKFLOW) 
static

Arguments

$aggressive

$workflow

Paging

limit(array $request,  $columns) 
static

Construct the LIMIT clause for server-side processing SQL query

Arguments

$request

array

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

$columns

Ordering

order(array $request,  $columns) 
static

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

Arguments

$request

array

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

$columns

Pull a particular property from each assoc. array in a numeric array, returning and array of the property values from each item.

pluck( $a, string $prop) 
static

@param array $a Array to get data from

Arguments

$a

$prop

string

Property to read @return array Array of property values

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.

simple( $request, string $table,  $primaryKey,  $columns) 
static

@param array $request Data sent to server by DataTables

Arguments

$request

$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

$columns

Connect to the database by PDO

sql_connect() : \PDO
static

Response

\PDO

Database connection handle

Execute an SQL query on the database

sql_exec(resource $dbpdo, array $bindings, string $sql = null) : array
static

Arguments

$dbpdo

resource

Database handler

$bindings

array

Array of PDO binding values from bind() to be used for safely escaping strings. Note that this can be given as the SQL query string if no bindings are required.

$sql

string

SQL query to execute.

Response

array

Result from the query (all rows)