Ejemplo n.º 1
0
 /**
  * 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) + [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;
 }