Documentation

SSP
in package

Class SSP

Table of Contents

_flatten()  : string
Return a string from an array or a string
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:
data_output()  : mixed
Create the data output array for the DataTables rows
db()  : mixed
Database connection
fatal()  : mixed
Throw a fatal error.
filter()  : mixed
Searching / Filtering
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()  : resource
Connect to the database
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

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 $conn, 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 array|PDO $conn PDO connection resource or connection parameters array @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

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

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

db()

Database connection

public static db(array<string|int, mixed> $conn) : mixed

Obtain an PHP PDO connection from a connection details array

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

SQL connection details. The array should have the following properties

  • host - host name
  • db - database name
  • user - user name
  • pass - user password @return resource PDO connection
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

limit()

Paging

public static limit(array<string|int, mixed> $request, mixed $columns) : 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

$columns : mixed
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, array<string|int, mixed>|PDO $conn, mixed $table, mixed $primaryKey, mixed $columns) : mixed

@param array $request Data sent to server by DataTables

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

PDO connection resource or connection parameters array @param string $table 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

$table : mixed
$primaryKey : mixed
$columns : mixed
Return values
mixed

sql_connect()

Connect to the database

public static sql_connect(array<string|int, mixed> $sql_details) : resource
Parameters
$sql_details : array<string|int, mixed>

SQL server connection details array, with the properties:

  • host - host name
  • db - database name
  • user - user name
  • pass - user password
Return values
resource

Database connection handle

sql_exec()

Execute an SQL query on the database

public static sql_exec(resource $db, array<string|int, mixed> $bindings[, string $sql = null ]) : array<string|int, mixed>
Parameters
$db : resource

Database handler

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

Search results