Methods
Method |
Parameters |
Parameter description |
Return |
Description |
|---|---|---|---|---|
quote |
•$value: mixed •[$type: null|string = null]: mixed |
•A literal string to quote •Type to which the value should be converted to |
mixed |
Quotes a literal string. This method is NOT meant to fix SQL injections! It is only meant to escape this platform's string literal quote character inside the given literal string. |
exec |
•$sql: string |
•SQL query |
mixed |
Executes an SQL statement and return the number of affected rows. |
query |
•$sql: string |
•SQL query |
false|ResultInterface |
Executes an SQL statement, returning a result set as a Statement object; otherwise a error. The error message can then be retrieved via getErrorMessage. |
fetchRow |
•$result: ResultInterface |
•Object returned by query() |
mixed |
Return a dataset from the result as an associative array. If there are no more datasets, a null will be returned, false will be returned on error. The error message can then be retrieved via getErrorMessage. |
fetchAll |
•$result: ResultInterface |
•Object returned by query() |
mixed |
Returns all rows of the query result. If an error occurs, the method returns false. The error message can then be retrieved via getErrorMessage. |
fetchOne |
•$result: ResultInterface |
•Object returned by query() |
mixed |
Returns the first column of the first data set. If an error occurs, the method returns false. The error message can then be retrieved via getErrorMessage. |
preparedSelect |
•$sql: string •$params: array •[$types: array|null = [...]] |
•SQL Query to prepare •SQL Query parameter •Optional sql query parameter types |
ResultInterface|false|int |
Prepares an optionally parametrized SQL selection and return prepared result set; otherwise an integer based on sql select statement or false. |
preparedExecute |
•$sql: string •$params: array •[$types: array|null = [...]] |
•SQL Query to prepare •SQL Query parameter •Optional sql query parameter types |
ResultInterface|int |
Executes an optionally parametrized SQL selection and return prepared result set; otherwise an integer based on sql select statement or false in case of error. |
getErrorMessage |
- |
- |
string |
Provides an additional user-supplied error information and return user-supplied error information; otherwise an empty if no error message exist. |
Example
<?php
use Doctrine\DBAL\Exception;
use JobRouter\Sdk\ConnectionManagerInterface;
use JobRouter\Sdk\ResultInterface;
return function (ConnectionManagerInterface $connectionManager): void {
echo '<h1 style="color: #fc0">SDK Example to demonstrate the ConnectionManagerInterface and JobDBInterface!</h1>';
echo '<h3 style="color: #fc0;">JobRouter Users (internal connection) - getJobDB()</h3>';
$jobDB = $connectionManager->getJobDB();
$result = $jobDB->query('SELECT COUNT(*) FROM JRUSERS');
$count = $jobDB->fetchOne($result);
// Do something with the $count
$result = $jobDB->query('SELECT lastname, prename, supervisor FROM JRUSERS');
if ($result === false) {
echo '<h3 style="color: #f44;">ERROR!</h3>';
echo '<p style="color: #f44;">Message: ' . $jobDB->getErrorMessage() . '</p>';
} else {
$users = $jobDB->fetchAll($result);
// Do something with the $users
}
try {
$preparedResult = $jobDB->preparedSelect(
'SELECT DISTINCT language_name FROM JRPROCESSLANGUAGES WHERE processname = :processname AND version = :version ORDER BY language_name',
[
'processname' => 'example_processname',
'version' => 1,
],
[
'text',
'integer',
],
);
$result = $preparedResult->fetchOne();
// Do something with the $result
} catch (\JobRouterException|Exception $e) {
echo '<h3 style="color: #f44;">ERROR!</h3>';
echo '<p style="color: #f44;">Message: ' . $e->getMessage() . '</p>';
}
echo '<h3 style="color: #59aa6e;">JobRouter (Global connection) - getDBConnection(\'GC_JOBDATA\')</h3>';
try {
$gcJobdata = $connectionManager->getDBConnection('GC_JOBDATA');
$data = $gcJobdata->query('SELECT COUNT(*) FROM DATA_TABLE');
$dataObject = $data->fetchOne();
// Do something with the $dataObject
} catch (\JobRouterException|Exception $e) {
echo '<h3 style="color: #f44;">ERROR!</h3>';
echo '<p style="color: #f44;">Message: ' . $e->getMessage() . '</p>';
}
echo '<h3 style="color: #59aa6e;">JobRouter (Global connection) - getDBConnection(\'GlobalConnectionFromJobRouterDosNotExists\')</h3>';
try {
$connectionManager->getDBConnection('GlobalConnectionFromJobRouterDosNotExists');
} catch (\JobRouterException|\Exception $e) {
echo '<h3 style="color: #f44;">ERROR!</h3>';
echo '<p style="color: #f44;">Message: ' . $e->getMessage() . '</p>';
}
};