expDatabase
in package
This is the expDatabase subsystem Handles all database abstraction in Exponent.
Tags
Table of Contents
- _flatten() : string
- Return a string from an array or a string
- backends() : array<string|int, mixed>
- List all available database backends
- bind() : string
- Create a PDO binding key which can be used for escaping variables safely when executing a query with sql_exec()
- complex() : 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:
- connect() : _database|database|stdClass
- Connect to the Exponent database
- data_output() : mixed
- Create the data output array for the DataTables rows
- fatal() : mixed
- Throw a fatal error.
- filter() : mixed
- Searching / Filtering
- fix_table_names() : mixed
- install_dbtables() : mixed
- limit() : mixed
- Paging
- order() : mixed
- Ordering
- pluck() : mixed
- Pull a particular property from each assoc. array in a numeric array, returning and array of the property values from each item.
- simple() : 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_connect() : PDO
- Connect to the database by PDO
- sql_exec() : array<string|int, mixed>
- Execute an SQL query on the database
Methods
_flatten()
Return a string from an array or a string
public
static _flatten(array<string|int, mixed>|string $a[, string $join = ' AND ' ]) : string
Parameters
- $a : array<string|int, mixed>|string
-
Array to join
- $join : string = ' AND '
-
Glue for the concatenation
Return values
string —Joined string
backends()
List all available database backends
public
static backends([int $valid_only = 1 ]) : array<string|int, mixed>
This function looks for available database engines, and then returns an array to the caller.
Parameters
- $valid_only : int = 1
Return values
array<string|int, mixed> —An associative array of engine identifiers. The internal engine name is the key, and the external descriptive name is the value.
bind()
Create a PDO binding key which can be used for escaping variables safely when executing a query with sql_exec()
public
static bind(array<string|int, mixed> &$a, mixed $val, int $type) : string
Parameters
- $a : array<string|int, mixed>
-
Array of bindings
- $val : mixed
- $type : int
-
PDO field type
Return values
string —Bound key to be used in the SQL where this parameter would be used.
complex()
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(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 —connect()
Connect to the Exponent database
public
static connect(string $username, string $password, string $hostname, string $database[, string $dbclass = '' ][, bool $new = false ][, null $log = null ]) : _database|database|stdClass
This function attempts to connect to the exponent database, and then returns the database object to the caller.
Parameters
- $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 : bool = false
- $log : null = null
Return values
_database|database|stdClass —data_output()
Create the data output array for the DataTables rows
public
static data_output(mixed $columns, array<string|int, mixed> $data) : mixed
@param array $columns Column information array
Parameters
- $columns : mixed
- $data : array<string|int, mixed>
-
Data from the SQL get @return array Formatted data in a row based format
Return values
mixed —fatal()
Throw a fatal error.
public
static fatal(string $msg) : mixed
This writes out an error message in a JSON string which DataTables will see and show to the user in the browser.
Parameters
- $msg : string
-
Message to send to the client
Return values
mixed —filter()
Searching / Filtering
public
static filter(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 —fix_table_names()
public
static fix_table_names() : mixed
Return values
mixed —install_dbtables()
public
static install_dbtables([mixed $aggressive = false ][, mixed $workflow = ENABLE_WORKFLOW ]) : mixed
Parameters
- $aggressive : mixed = false
- $workflow : mixed = ENABLE_WORKFLOW
Return values
mixed —limit()
Paging
public
static limit(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 @param array $columns Column information array @return string SQL limit clause
Return values
mixed —order()
Ordering
public
static order(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 —pluck()
Pull a particular property from each assoc. array in a numeric array, returning and array of the property values from each item.
public
static pluck(mixed $a, string $prop) : mixed
@param array $a Array to get data from
Parameters
- $a : mixed
- $prop : string
-
Property to read @return array Array of property values
Return values
mixed —simple()
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(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_connect()
Connect to the database by PDO
public
static sql_connect() : PDO
Return values
PDO —Database connection handle
sql_exec()
Execute an SQL query on the database
public
static sql_exec(mixed $dbpdo, array<string|int, mixed> $bindings[, string $sql = null ]) : array<string|int, mixed>
Parameters
- $dbpdo : mixed
- $bindings : array<string|int, mixed>
-
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 = null
-
SQL query to execute.
Return values
array<string|int, mixed> —Result from the query (all rows)