, DataTables JOIN WHERE, ssp.class.php . API, , . "SSP:: simple" "SSP:: complex" "SSP:: process".
- script pastebin.com : ssp.class. PHP
, :
private function get_recent_payments() {
global
$pdoHost, $pdoUser,
$pdoPass, $pdoDatabase;
$sql_details = array(
'user' => $pdoUser,
'pass' => $pdoPass,
'db' => $pdoDatabase,
'host' => $pdoHost
);
require_once('ssp.class.php');
$options = [
'table' => 'payments',
'alias' => 'l',
'primaryKey' => 'id',
'columns' => [
[ 'db' => 'id', 'dt' => 0 ],
[
'db' => 'client_id',
'dt' => 1,
'join' => [
'table' => 'clients',
'on' => 'id',
'select' => 'first_name',
'alias' => 'c',
'as' => 'fname',
]
],
[
'db' => 'client_id',
'dt' => 2,
'join' => [
'table' => 'clients',
'on' => 'id',
'select' => 'last_name',
'alias' => 'c'
]
],
[ 'db' => 'pay_date', 'dt' => 3 ]
],
'where' => [
[
'db' => 'client_id',
'op' => '!=',
'value' => $_SESSION['client_id']
]
]
];
$this->response(SSP::process($_REQUEST, $sql_details, $options));
}
The "where" and "whereResult" parameters (SEE "SSP :: complex" for details) can also have an "alias" to refer to a column in a joined table.
An example of an SQL query passed to the server:
SELECT l.`id`, c.`first_name` AS 'fname', c.`last_name`, l.`pay_date`
FROM `payments` l
JOIN `clients` c ON (c.`id` = l.`client_id`)
WHERE l.`client_id` != :binding_0
ORDER BY l.`pay_date` DESC
LIMIT 0, 5
I took the route of a structured array because it allowed me to create queries, while maintaining the rigidity of the queries with backticks and associated operator parameters. I am raising this post in the hope that others will find it useful, as I am.