mirror of
https://github.com/grocy/grocy.git
synced 2025-10-11 00:05:04 +00:00
Added the possibility to log executed SQL statements (DEV mode only)
This commit is contained in:
@@ -29,9 +29,18 @@ class DatabaseService
|
||||
{
|
||||
$pdo = $this->GetDbConnectionRaw();
|
||||
|
||||
if (GROCY_MODE === 'dev')
|
||||
{
|
||||
$logFilePath = GROCY_DATAPATH . '/sql.log';
|
||||
if (file_exists($logFilePath))
|
||||
{
|
||||
file_put_contents($logFilePath, $sql . PHP_EOL, FILE_APPEND);
|
||||
}
|
||||
}
|
||||
|
||||
if ($pdo->exec($sql) === false)
|
||||
{
|
||||
throw new Exception($pdo->errorInfo());
|
||||
throw new \Exception($pdo->errorInfo());
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -49,6 +58,17 @@ class DatabaseService
|
||||
self::$DbConnection = new Database($this->GetDbConnectionRaw());
|
||||
}
|
||||
|
||||
if (GROCY_MODE === 'dev')
|
||||
{
|
||||
$logFilePath = GROCY_DATAPATH . '/sql.log';
|
||||
if (file_exists($logFilePath))
|
||||
{
|
||||
self::$DbConnection->setQueryCallback(function ($query, $params) use ($logFilePath) {
|
||||
file_put_contents($logFilePath, $query . ' #### ' . implode(';', $params) . PHP_EOL, FILE_APPEND);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return self::$DbConnection;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user