hasDb()) { throw new LogicException('Please check if a db instance exists at all'); } $config = new SqlConfig(ResourceFactory::getResourceConfig( IcingaConfig::app()->get('global', 'config_resource') )); if ($config->db === 'mysql') { $config->charset = 'utf8mb4'; } $config->options = [PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ]; if ($config->db === 'mysql') { $config->options[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'"; } return new Connection($config); } /** * Check if db exists * * @return bool true if a database was found otherwise false */ protected function hasDb() { return (bool) IcingaConfig::app()->get('global', 'config_resource'); } }