Beispiel #1
0
 /**
  * Set character set
  *
  * @return bool true on success, false otherwise
  */
 private function setCharset()
 {
     $charset = strtolower($this->_charset);
     if (!in_array($charset, array('utf-8', 'utf8', 'utf8mb4'))) {
         return true;
     }
     if ($charset === 'utf-8') {
         // before GL-2.1.2
         $charset = 'utf8';
     } elseif ($charset === 'utf8mb4') {
         // since GL-2.1.2
         if ($this->_mysql_version < 50503) {
             $charset = 'utf8';
         }
     }
     $this->_charset = $charset;
     $retval = false;
     if (method_exists($this->_db, 'set_charset')) {
         $retval = @$this->_db->set_charset($charset);
     }
     if (!$retval) {
         $retval = @$this->_db->query("SET NAMES '{$this->_charset}'");
     }
     return $retval;
 }
Beispiel #2
0
 /**
  * Connects to the MySQL database server
  *
  * This function connects to the MySQL server and returns the connection object
  *
  * @return   object      Returns connection object
  * @access   private
  */
 private function _connect()
 {
     if ($this->_verbose) {
         $this->_errorlog("DEBUG: mysqli - inside database->_connect");
     }
     // Connect to MySQL server
     $this->_db = @new mysqli($this->_host, $this->_user, $this->_pass);
     if ($this->_db->connect_errno) {
         die('Connect Error: ' . $this->_db->connect_errno);
     }
     $this->_mysql_version = $this->_db->server_version;
     // Set the database
     $this->_db->select_db($this->_name) or die('error selecting database');
     if (!$this->_db) {
         if ($this->_verbose) {
             $this->_errorlog("DEUBG: mysqli - error in database->_connect");
         }
         // damn, got an error.
         $this->dbError();
     }
     if ($this->_charset === 'utf-8') {
         $result = false;
         if (method_exists($this->_db, 'set_charset')) {
             $result = $this->_db->set_charset('utf8');
         }
         if (!$result) {
             @$this->_db->query("SET NAMES 'utf8'");
         }
     }
     if ($this->_mysql_version >= 50700) {
         $result = $this->_db->query("SELECT @@sql_mode");
         $modeData = $this->dbFetchArray($result);
         $updatedMode = '';
         $first = 0;
         $found = 0;
         if (isset($modeData["@@sql_mode"])) {
             $modeArray = explode(",", $modeData["@@sql_mode"]);
             foreach ($modeArray as $setting) {
                 if ($setting == 'ONLY_FULL_GROUP_BY') {
                     $found = 1;
                     continue;
                 }
                 if ($first != 0) {
                     $updatedMode .= ',';
                 }
                 $updatedMode .= $setting;
                 $first++;
             }
             if ($found == 1) {
                 @$this->_db->query("SET sql_mode = '" . $updatedMode . "'");
             }
         }
     }
     if ($this->_verbose) {
         $this->_errorlog("DEBUG: mysqli - leaving database->_connect");
     }
 }
Beispiel #3
0
 /**
  * Connects to the MySQL database server
  * This function connects to the MySQL server and returns the connection object
  *
  * @return   object      Returns connection object
  * @access   private
  */
 private function _connect()
 {
     global $_TABLES, $use_innodb;
     if ($this->_verbose) {
         $this->_errorlog("\n*** Inside database->_connect ***");
     }
     // Connect to MySQL server
     $this->_db = new mysqli($this->_host, $this->_user, $this->_pass);
     if (!$this->_db instanceof mysqli) {
         die('Cannot connect to DB server');
     }
     $this->_mysql_version = $this->_db->server_version;
     // Set the database
     $this->_db->select_db($this->_name) || die('error selecting database');
     if (!$this->_db) {
         if ($this->_verbose) {
             $this->_errorlog("\n*** Error in database->_connect ***");
         }
         // damn, got an error.
         $this->dbError();
     }
     if ($this->_mysql_version >= 40100) {
         if ($this->_charset === 'utf-8') {
             $result = false;
             if (method_exists($this->_db, 'set_charset')) {
                 $result = $this->_db->set_charset('utf8');
             }
             if (!$result) {
                 @$this->_db->query("SET NAMES 'utf8'");
             }
         }
     }
     // Checks if db engine is InnoDB.  During the installation
     // $_TABLES['vars'] is not yet created, so we use $use_innodb instead.
     if (isset($use_innodb)) {
         $this->_use_innodb = (bool) $use_innodb;
     } else {
         if ($this->dbTableExists('vars')) {
             $result = $this->dbQuery("SELECT value FROM {$_TABLES['vars']} WHERE (name = 'database_engine')");
             if ($result !== false && $this->dbNumRows($result) == 1) {
                 $A = $this->dbFetchArray($result, false);
                 $this->_use_innodb = strcasecmp($A['value'], 'InnoDB') === 0;
             }
         }
     }
     if ($this->_verbose) {
         $this->_errorlog("\n***leaving database->_connect***");
     }
 }