Please note: We recommend the Use of Prepared Statements. The method preparedSelect is available for this purpose.
To fetch data use the method query, which you can execute on the previously instantiated $jobDB class. Pass the SQL statement to be executed as parameter to the method.
Parameter |
Type |
Description |
|---|---|---|
$sql |
string |
SQL statement |
The return value is an object, which can be used to process data. In case of an error it will return false.
Example:
…
$sql = 'SELECT * FROM JRUSERS';
$result = $jobDB->query($sql);
…
When executing an SQL statement, you should always check if it was successful. To change the step to error status in case of an error, enter the following rows after executing the statement.
if ($result == false) {
throw new JobRouterException($jobDB->getErrorMessage());
}
Example:
…
$sql = 'SELECT * FROM JRUSERS';
$result = $jobDB->query($sql);
if ($result == false) {
throw new JobRouterException($jobDB->getErrorMessage());
}
…
To process the results of a query, use the method fetchRow for the result label. An array is returned that contains all columns of your query. You can access all columns of the result by using a while loop.
Example:
…
$sql = 'SELECT * FROM JRUSERS';
$result = $jobDB->query($sql);
if ($result == false) {
throw new JobRouterException($jobDB->getErrorMessage());
}
while ($row = $jobDB->fetchRow($result)) {
$user = $row['username'];
}
…