From 026bdf4cf2ef2f99ce41f0420553f0d849d12792 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Wed, 27 Nov 2019 13:19:06 +0100 Subject: [PATCH] Add trait for the database connection --- library/Icingadb/Common/Database.php | 43 ++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 library/Icingadb/Common/Database.php diff --git a/library/Icingadb/Common/Database.php b/library/Icingadb/Common/Database.php new file mode 100644 index 00000000..656e8c58 --- /dev/null +++ b/library/Icingadb/Common/Database.php @@ -0,0 +1,43 @@ +db === null) { + $config = new SqlConfig(ResourceFactory::getResourceConfig( + AppConfig::module('icingadb')->get('icingadb', 'resource', 'icingadb') + )); + + $config->options = [ + PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ, + PDO::MYSQL_ATTR_INIT_COMMAND => "SET SESSION SQL_MODE='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE" + . ",ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'" + ]; + + $this->db = new Connection($config); + } + + return $this->db; + } +}