To execute SQL statements use the function preparedExecute for manipulating data (UPDATE, INSERT or DELETE statements). This function can then be executed on the previously instantiated object $jobDB.
Parameter |
Type |
Description |
|---|---|---|
$sql |
string |
SQL statement (UPDATE, INSERT or DELETE statements) |
$parameterValues |
array |
The values that are to be resolved in the SQL statement are stored there. |
$parameterTypes (optional) |
array |
The data types for the values are stored there.
The following data types are available: •text (ConnectionInterface::TYPE_TEXT) •integer (ConnectionInterface::TYPE_INTEGER) •timestamp (ConnectionInterface::TYPE_DATETIME) •decimal (ConnectionInterface::TYPE_DECIMAL) •clob (ConnectionInterface::TYPE_CLOB))
Please note: The order of the values ($parameterValues) must correspond to the order of the data types ($parameterTypes), otherwise incorrect or faulty SQLs may result. We recommend that you specify the data types, even if the parameter is optional. |
In case of an error a JobRouterException is thrown.
Example:
…
$jobDB = $this->getJobDB();
$sql = 'UPDATE JRUSERS SET blocked = :blocked WHERE username = :username';
$parameters = [
'blocked' => 0,
'username' => 'some_username_here'
];
$types = [
JobRouter\Common\Database\ConnectionInterface::TYPE_INTEGER,
JobRouter\Common\Database\ConnectionInterface::TYPE_TEXT,
];
$jobDB->preparedExecute($sql, $parameters, $types);
…