function getDb() { if (!$this->_db) { $dsn = array(); $dsn['scheme'] = 'mysql'; $dsn['path'] = $this->getConfig('db'); if ($this->getConfig('other_db') == "1") { $dsn = array_merge($dsn, array('host' => $this->getConfig('host'), 'user' => $this->getConfig('user'), 'pass' => $this->getConfig('pass'))); } else { $appOptions = $this->getDi()->getParameters(); $dbConfig = $appOptions['db']['mysql']; $dsn = array_merge($dsn, array('host' => $dbConfig['host'], 'user' => $dbConfig['user'], 'pass' => $dbConfig['pass'])); if (isset($dbConfig['port']) && $dbConfig['port']) { $dsn['port'] = $dbConfig['port']; } } if ($dsn['host'] && strpos($dsn['host'], ':') !== false && preg_match('/\\:(\\d+)$/', $dsn['host'])) { list($dsn['host'], $dsn['port']) = explode(':', $dsn['host']); } $this->_db = Am_Db::connect($dsn, true); $this->_db->setErrorHandler(array($this, 'dbErrorHandler')); $this->_db->setIdentPrefix($this->getConfig('prefix')); $this->_db->query("USE ?#", $dsn['path']); $this->_db->query("SET NAMES utf8"); $this->_db->query("SET SESSION sql_mode=''"); } if ($this->sqlDebug) { if (!empty($this->getDi()->db->_logger)) { $this->_db->setLogger($this->getDi()->db->_logger); } } return $this->_db; }
function getDb() { if (!$this->_db) { $dsn = array(); $dsn['scheme'] = 'mysql'; $dsn['path'] = $this->getConfig('db'); if ($this->getConfig('other_db') == "1") { $dsn = array_merge($dsn, array('host' => $this->getConfig('host'), 'user' => $this->getConfig('user'), 'pass' => $this->getConfig('pass'))); } else { $appOptions = $this->getDi()->getParameters(); $dbConfig = $appOptions['db']['mysql']; $dsn = array_merge($dsn, array('host' => $dbConfig['host'], 'user' => $dbConfig['user'], 'pass' => $dbConfig['pass'])); } $this->_db = Am_Db::connect($dsn, true); $this->_db->setErrorHandler(array($this, 'dbErrorHandler')); $this->_db->setIdentPrefix($this->getConfig('prefix')); $this->_db->query("USE ?#", $dsn['path']); } if ($this->sqlDebug) { if (!empty($this->getDi()->db->_logger)) { $this->_db->setLogger($this->getDi()->db->_logger); } } return $this->_db; }