/**
* Execute an sql query in the database. The correct database connection
* will be chosen and the query will be logged with the success status.
*
* As third parameter an alternative query can be passed, which should be
* displayed instead of the executed query. This prevents leakage of
* confidential information like password salts. The logfile will still
* contain the executed query.
*
* @param $query query to execute as string
* @param bool $errorProcessing true if it's an error when the query fails.
* @param null $displayQuery
*/
function exec_query($query, $errorProcessing = true, $displayQuery = null)
{
global $database, $kga, $errors, $executed_queries;
$conn = $database->getConnectionHandler();
$executed_queries++;
$success = $conn->Query($query);
Kimai_Logger::logfile($query);
$err = $conn->Error();
$query = htmlspecialchars($query);
$displayQuery = htmlspecialchars($displayQuery);
if ($success) {
$level = 'green';
} else {
if ($errorProcessing) {
$level = 'red';
$errors++;
} else {
$level = 'orange';
// something went wrong but it's not an error
}
}
printLine($level, $displayQuery == null ? $query : $displayQuery, $err);
if (!$success) {
Kimai_Logger::logfile("An error has occured in query [{$query}]: " . $conn->Error());
}
}