Exemplo n.º 1
0
 /**
  * Execute SQL query
  * @category WoW Database Handler
  * @access   private
  * @param    string $safe_sql
  * @param    int $queryType
  * @return   mixed
  **/
 private function _query($safe_sql, $queryType)
 {
     // Execute query and calculate execution time
     $make_array = array();
     $query_start = microtime(true);
     $this->queryCount++;
     if ($this->driver_type == 'mysqli') {
         $performed_query = @mysqli_query($this->connectionLink, $safe_sql);
         $this->errmsg = @mysqli_error($this->connectionLink);
         $this->errno = @mysqli_errno($this->connectionLink);
     } else {
         $performed_query = @mysql_query($safe_sql, $this->connectionLink);
         $this->errmsg = @mysql_error($this->connectionLink);
         $this->errno = @mysql_errno($this->connectionLink);
     }
     if (!$performed_query) {
         WoW_Log::WriteLog('%s : unable to execute SQL query (%s). MySQL error: %s', __METHOD__, $safe_sql, $this->errmsg ? sprintf('"%s" (Error #%d)', $this->errmsg, $this->errno) : 'none');
         return false;
     }
     $result = false;
     switch ($queryType) {
         case SINGLE_CELL:
             if ($this->driver_type == 'mysqli') {
                 $tmp = @mysqli_fetch_array($performed_query);
                 // this works faster than mysql_result
             } else {
                 $tmp = @mysql_fetch_array($performed_query);
                 // this works faster than mysql_result
             }
             $result = $tmp[0];
             unset($tmp);
             break;
         case SINGLE_ROW:
             if ($this->driver_type == 'mysqli') {
                 $result = @mysqli_fetch_assoc($performed_query);
             } else {
                 $result = @mysql_fetch_assoc($performed_query);
             }
             if (is_array($result)) {
                 foreach ($result as $rKey => $rValue) {
                     if (is_string($rKey)) {
                         $make_array[$rKey] = $rValue;
                     }
                 }
                 $result = $make_array;
             }
             break;
         case MULTIPLY_ROW:
             $result = array();
             if ($this->driver_type == 'mysqli') {
                 while ($_result = @mysqli_fetch_assoc($performed_query)) {
                     if (is_array($_result)) {
                         foreach ($_result as $rKey => $rValue) {
                             if (is_string($rKey)) {
                                 $make_array[$rKey] = $rValue;
                             }
                         }
                         $result[] = $make_array;
                     } else {
                         $result[] = $_result;
                     }
                 }
             } else {
                 while ($_result = @mysql_fetch_assoc($performed_query)) {
                     if (is_array($_result)) {
                         foreach ($_result as $rKey => $rValue) {
                             if (is_string($rKey)) {
                                 $make_array[$rKey] = $rValue;
                             }
                         }
                         $result[] = $make_array;
                     } else {
                         $result[] = $_result;
                     }
                 }
             }
             break;
         case OBJECT_QUERY:
             $result = array();
             if ($this->driver_type == 'mysqli') {
                 while ($_result = @mysqli_fetch_object($performed_query)) {
                     $result[] = $_result;
                 }
             } else {
                 while ($_result = @mysql_fetch_object($performed_query)) {
                     $result[] = $_result;
                 }
             }
             break;
         case SQL_QUERY:
             $result = true;
             break;
         default:
             $result = false;
             break;
     }
     $query_end = microtime(true);
     $queryTime = round($query_end - $query_start, 4);
     WoW_Log::WriteSql('[%s ms]: %s', $queryTime, $safe_sql);
     $this->queryTimeGeneration += $queryTime;
     unset($performed_query);
     return $result;
 }