Beispiel #1
0
 /**
  * @return Omeka_Db
  */
 public function init()
 {
     $dbFile = $this->_iniPath;
     if (!file_exists($dbFile)) {
         throw new Zend_Config_Exception('Your Omeka database configuration file is missing.');
     }
     if (!is_readable($dbFile)) {
         throw new Zend_Config_Exception('Your Omeka database configuration file cannot be read by the application.');
     }
     $dbIni = new Zend_Config_Ini($dbFile, 'database');
     // Fail on improperly configured db.ini file
     if (!isset($dbIni->host) || $dbIni->host == 'XXXXXXX') {
         throw new Zend_Config_Exception('Your Omeka database configuration file has not been set up properly.  Please edit the configuration and reload this page.');
     }
     $connectionParams = $dbIni->toArray();
     // dbname aliased to 'name' for backwards-compatibility.
     if (array_key_exists('name', $connectionParams)) {
         $connectionParams['dbname'] = $connectionParams['name'];
     }
     $bootstrap = $this->getBootstrap();
     $bootstrap->bootstrap('Config');
     $config = $this->getBootstrap()->getResource('Config');
     $loggingEnabled = $config->log->sql;
     $profilingEnabled = $config->debug->profileDb;
     if ($profilingEnabled) {
         $connectionParams['profiler'] = true;
     }
     $dbh = Zend_Db::factory('Mysqli', $connectionParams);
     $db_obj = new Omeka_Db($dbh, $dbIni->prefix);
     // Enable SQL logging (potentially).
     if ($loggingEnabled) {
         $bootstrap->bootstrap('Logger');
         $db_obj->setLogger($bootstrap->getResource('Logger'));
     }
     Zend_Db_Table_Abstract::setDefaultAdapter($dbh);
     return $db_obj;
 }
Beispiel #2
0
 private function _enableSqlLogging(Omeka_Db $db)
 {
     $bs = $this->getBootstrap();
     $loggingEnabled = ($config = $bs->getResource('Config')) && $config->log->sql;
     if ($loggingEnabled) {
         $bs->bootstrap('Logger');
         $db->setLogger($bs->getResource('Logger'));
     }
 }