'IP', * 'port' => '3306', * 'dbname' => 'db', * 'charset' => 'utf8', * 'user' => 'user', * 'password' => 'password', * @return boolean|PDO */ public function __construct(array $config = array()) { $user = null; $password = null; $options = array(); // Get Application config from registry if (count($config) == 0) { $c = Zend_Registry::get('config'); $params = $c->profil->db->metier->params; $dsn = "mysql:host=".$params->host. ";port=".(isset($params->port) ? $params->port : '3306'). ";dbname=".$params->dbname. ";charset=utf8"; $user = $params->username; $password = $params->password; } // Get config from params else { $dsn = "mysql:host=".$config['host']. ";port=".(isset($config['port']) ? $config['port'] : '3306'). ";dbname=".$config['dbname']. ";charset=".(isset($config['charset']) ? $config['charset'] : 'utf8'); if (array_key_exists('username', $config)) { $user = $config['username']; } if (array_key_exists('password', $config)) { $password = $config['password']; } if (array_key_exists('options', $config)) { $options = $config['options']; } } // Try to load PDO try { $this->conn = new PDO($dsn, $user, $password, $options); $this->conn->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); } catch (PDOException $e) { echo $e->getMessage(); $this->conn = false; } } /** * Get connection * @return PDO */ public function getConnection() { return $this->conn; } }