protected function _initDb() { $file = APPLICATION_PATH . '/application/settings/database.php'; $options = (include $file); $db = Zend_Db::factory($options['adapter'], $options['params']); Engine_Db_Table::setDefaultAdapter($db); Engine_Db_Table::setTablePrefix($options['tablePrefix']); // Non-production if (APPLICATION_ENV !== 'production') { $db->setProfiler(array('class' => 'Zend_Db_Profiler_Firebug', 'enabled' => true)); } // set DB to UTC timezone for this session switch ($options['adapter']) { case 'mysqli': case 'mysql': case 'pdo_mysql': $db->query("SET time_zone = '+0:00'"); break; case 'postgresql': $db->query("SET time_zone = '+0:00'"); break; default: // do nothing } // attempt to disable strict mode try { $db->query("SET SQL_MODE = ''"); } catch (Exception $e) { } return $db; }
protected function _initDb() { if (file_exists(APPLICATION_PATH . '/application/settings/database.php')) { $config = (include APPLICATION_PATH . '/application/settings/database.php'); if (!empty($config['adapter'])) { try { $db = Zend_Db::factory($config['adapter'], $config['params']); $db->getServerVersion(); // Forces the connection open } catch (Exception $e) { $this->getContainer()->log->log($e, Zend_Log::WARN); return; } Zend_Registry::set('Zend_Db', $db); // set DB to UTC timezone for this session switch ($config['adapter']) { case 'mysqli': case 'mysql': case 'pdo_mysql': $db->query("SET time_zone = '+0:00'"); break; case 'postgresql': $db->query("SET time_zone = '+0:00'"); break; default: // do nothing } // attempt to disable strict mode try { $db->query("SET SQL_MODE = ''"); } catch (Exception $e) { } Engine_Db_Table::setDefaultAdapter($db); return $db; } } }