Log SQL warnings to the error log, but only in development

This commit is contained in:
Starbeamrainbowlabs 2019-06-30 17:24:02 +01:00
parent e86b0b4f97
commit 74b1b212fe
Signed by: sbrl
GPG key ID: 1BE5172E637709C2

View file

@ -88,6 +88,12 @@ class Database
// FUTURE: Optionally cache prepared statements? // FUTURE: Optionally cache prepared statements?
$statement = $this->connection->prepare($sql); $statement = $this->connection->prepare($sql);
$statement->execute($variables); $statement->execute($variables);
if($this->settings->get("env.mode") == "development") {
$warnings = $this->connection->query("SHOW WARNINGS;")->fetchAll();
error_log("Warnings: " . var_export($warnings, true));
}
return $statement; // fetchColumn(), fetchAll(), etc. are defined on the statement, not the return value of execute() return $statement; // fetchColumn(), fetchAll(), etc. are defined on the statement, not the return value of execute()
} }