Exemplo n.º 1
0
 /**
  *
  * {@inheritdoc}
  *
  * @see \vxPHP\Database\DatabaseInterface::__construct()
  */
 public function __construct(array $config)
 {
     parent::__construct($config);
     $this->dsn = sprintf("%s:dbname=%s;host=%s", 'pgsql', $this->dbname, $this->host);
     if ($this->port) {
         $this->dsn .= ';port=' . $this->port;
     }
     $options = [\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION, \PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC];
     $connection = new \PDO($this->dsn, $this->user, $this->pass, $options);
     $connection->setAttribute(\PDO::ATTR_STRINGIFY_FETCHES, FALSE);
     $this->connection = $connection;
 }
Exemplo n.º 2
0
 /**
  * initiate connection
  * 
  * @todo parse unix_socket settings
  * 
  * @param array $config
  * @throws \PDOException
  */
 public function __construct(array $config = [])
 {
     parent::__construct($config);
     if (defined('DEFAULT_ENCODING')) {
         if (!is_null($this->charsetMap[strtolower(DEFAULT_ENCODING)])) {
             $charset = $this->charsetMap[strtolower(DEFAULT_ENCODING)];
         } else {
             throw new \PDOException(sprintf("Character set '%s' not mapped or supported.", DEFAULT_ENCODING));
         }
     } else {
         $charset = 'utf8';
     }
     $this->dsn = sprintf("%s:dbname=%s;host=%s;charset=%s", 'mysql', $this->dbname, $this->host, $charset);
     if ($this->port) {
         $this->dsn .= ';port=' . $this->port;
     }
     $options = [\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION, \PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC];
     $connection = new \PDO($this->dsn, $this->user, $this->pass, $options);
     $connection->setAttribute(\PDO::ATTR_STRINGIFY_FETCHES, FALSE);
     // set emulated prepares for MySQL servers < 5.1.17
     $connection->setAttribute(\PDO::ATTR_EMULATE_PREPARES, version_compare($connection->getAttribute(\PDO::ATTR_SERVER_VERSION), '5.1.17', '<'));
     $this->connection = $connection;
 }