示例#1
0
 /**
  * Do real connection to Db server.
  *
  * @throws DbLinkException Thrown when no connection is possible.
  */
 public function connect()
 {
     if (!$this->is_connected) {
         $this->link->real_connect($this->host, $this->user, $this->pass, $this->schema, $this->port);
         if ($this->link->connect_error) {
             $this->errors[] = $this->link->connect_error;
             throw new DbLinkException($this->link->connect_error, $this->link->connect_errno);
         }
         $this->link->set_charset(self::DEFAULT_CHARSET);
         $this->is_connected = true;
     }
 }
示例#2
0
 /**
  * Create the database connection, select the appropriate db and call setOptions
  * @param string $dbHost
  * @param string $dbUname
  * @param string $dbPass
  * @param string $dbName
  * @param string $dbPort
  * @return void
  */
 public function initialize($dbHost, $dbUname, $dbPass, $dbName, $dbPort)
 {
     $this->connection = mysqli_init();
     if (!$this->connection->options(MYSQLI_INIT_COMMAND, 'set names utf8, collation_connection=utf8_unicode_ci')) {
         trigger_error('MySQLi_options call failed');
     }
     $this->connection->options(MYSQLI_OPT_CONNECT_TIMEOUT, 2);
     $this->connection->real_connect($dbHost, $dbUname, $dbPass, $dbName, $dbPort);
     $this->connection->set_charset('utf8');
     if (mysqli_connect_errno()) {
         trigger_error('Unable to connect to MySQL: ' . mysqli_connect_error() . " H:'" . $_SERVER['HTTP_HOST'] . "'");
         die;
     }
     $this->dbOnline = true;
 }