/** * Connects to the database by constructing DSN string and creating a PDO intance using * the parent class. Will set specific options on the connection as provided (timezone, * schema). * * @see lithium\data\source\dataase\adapter\PostgreSql::timezone() * @return boolean Returns `true` if a database connection could be established, * otherwise `false`. */ public function connect() { if (!$this->_config['dsn']) { $host = $this->_config['host']; list($host, $port) = explode(':', $host) + array(1 => "5432"); $dsn = "pgsql:host=%s;port=%s;dbname=%s"; $this->_config['dsn'] = sprintf($dsn, $host, $port, $this->_config['database']); } if (!parent::connect()) { return false; } if ($this->_config['schema']) { $this->searchPath($this->_config['schema']); } if ($this->_config['timezone']) { $this->timezone($this->_config['timezone']); } return true; }
/** * Connects to the database by constructing DSN string and creating a PDO intance using * the parent class. Will set specific options on the connection as provided. * * @return boolean Returns `true` if a database connection could be established, * otherwise `false`. */ public function connect() { if (!$this->_config['dsn']) { $this->_config['dsn'] = $this->_dsn(); } return parent::connect(); }
/** * Connects to the database using the options provided to the class constructor. * * @return boolean Returns `true` if a database connection could be established, otherwise * `false`. */ public function connect() { if (!$this->_config['dsn']) { $host = $this->_config['host']; list($host, $port) = explode(':', $host) + array(1 => "3306"); $dsn = "mysql:host=%s;port=%s;dbname=%s"; $this->_config['dsn'] = sprintf($dsn, $host, $port, $this->_config['database']); } if (!parent::connect()) { return false; } $info = $this->connection->getAttribute(PDO::ATTR_SERVER_VERSION); $this->_useAlias = (bool) version_compare($info, "4.1", ">="); return true; }
/** * Connects to the database using options provided to the class constructor. * * @return boolean True if the database could be connected, else false */ public function connect() { if (!$this->_config['database']) { throw new ConfigException('No Database configured'); } if (empty($this->_config['dsn'])) { $this->_config['dsn'] = sprintf("sqlite:%s", $this->_config['database']); } return parent::connect(); }
/** * Connects to the database by constructing DSN string and creating a PDO intance using * the parent class. Will set specific options on the connection as provided. * * @return boolean Returns `true` if a database connection could be established, * otherwise `false`. */ public function connect() { if (!$this->_config['dsn']) { $host = $this->_config['host']; list($host, $port) = explode(':', $host) + array(1 => "3306"); $dsn = "mysql:host=%s;port=%s;dbname=%s"; $this->_config['dsn'] = sprintf($dsn, $host, $port, $this->_config['database']); } return parent::connect(); }