Esempio n. 1
0
 /**
  * @see MysqlManager::query()
  */
 protected function queryMulti($sql, $dieOnError = false, $msg = '', $suppress = false, $keepResult = false, $multiquery = true)
 {
     if (is_array($sql)) {
         return $this->queryArray($sql, $dieOnError, $msg, $suppress);
         //queryArray does not support any return sets
     }
     static $queryMD5 = array();
     parent::countQuery($sql);
     $GLOBALS['log']->info('Query:' . $sql);
     $this->checkConnection();
     $this->query_time = microtime(true);
     $this->lastsql = $sql;
     if ($multiquery) {
         $query_result = $suppress ? @mysqli_multi_query($this->database, $sql) : mysqli_multi_query($this->database, $sql);
         $result = mysqli_use_result($this->database);
         // Clear any remaining recordsets
         while (mysqli_next_result($this->database)) {
             $tmp_result = mysqli_use_result($this->database);
             mysqli_free_result($tmp_result);
         }
     } else {
         $result = $suppress ? @mysqli_query($this->database, $sql) : mysqli_query($this->database, $sql);
     }
     $md5 = md5($sql);
     if (empty($queryMD5[$md5])) {
         $queryMD5[$md5] = true;
     }
     $this->query_time = microtime(true) - $this->query_time;
     $GLOBALS['log']->info('Query Execution Time:' . $this->query_time);
     // slow query logging
     if ($this->dump_slow_queries($sql)) {
         $this->track_slow_queries($sql);
     }
     // This is some heavy duty debugging, leave commented out unless you need this:
     /*
       $bt = debug_backtrace();
       $line['file'] = 'NO_FILE';
       $line['line'] = 'NO_LINE';
       $line['function'] = 'NO_FUNCTION';
       $i = 0;
       foreach ( $bt as $i => $tryLine ) {
           if ( strpos($tryLine['file'],'include/database') === false && strpos($tryLine['file'],'include/SugarQuery') === false ) {
               $line = $tryLine;
               // Go function line up to find the real function
               if ( isset($bt[($i+1)]['function']) ) {
                   $line['function'] = $bt[($i+1)]['function'];
               }
               break;
           }
       }
     $dumpQuery = str_replace(array('      ','     ','    ','   ','  ',"\n","\t","\r"),
                              array(' ',     ' ',    ' ',   ' ',  ' ', ' ', ' ', ' ',),
                              $sql);
     
     $GLOBALS['log']->fatal("{$line['file']}:{$line['line']} ${line['function']} \nQuery: $dumpQuery\n");
     */
     if ($keepResult) {
         $this->lastResult = $result;
     }
     if ($this->database && mysqli_errno($this->database) == 2006 && $this->retryCount < 1) {
         $GLOBALS['log']->fatal('mysqli has gone away, retrying');
         $this->retryCount++;
         $this->disconnect();
         $this->connect();
         return $this->query($sql, $dieOnError, $msg, $suppress, $keepResult);
     } else {
         $this->retryCount = 0;
     }
     $this->checkError($msg . ' Query Failed: ' . $sql, $dieOnError);
     return $result;
 }
Esempio n. 2
0
 /**
  * @see MysqlManager::query()
  */
 public function query($sql, $dieOnError = false, $msg = '', $suppress = false, $autofree = false)
 {
     static $queryMD5 = array();
     parent::countQuery($sql);
     $GLOBALS['log']->info('Query:' . $sql);
     $this->checkConnection();
     //$this->freeResult();
     $this->query_time = microtime(true);
     $this->lastsql = $sql;
     if ($suppress == true) {
     } else {
         $result = mysqli_query($this->database, $sql);
     }
     $md5 = md5($sql);
     if (empty($queryMD5[$md5])) {
         $queryMD5[$md5] = true;
     }
     $this->lastmysqlrow = -1;
     $this->query_time = microtime(true) - $this->query_time;
     $GLOBALS['log']->info('Query Execution Time:' . $this->query_time);
     // This is some heavy duty debugging, leave commented out unless you need this:
     /*
     $bt = debug_backtrace();
     for ( $i = count($bt) ; $i-- ; $i > 0 ) {
         if ( strpos('MysqliManager.php',$bt[$i]['file']) === false ) {
             $line = $bt[$i];
         }
     }
     
     $GLOBALS['log']->fatal("${line['file']}:${line['line']} ${line['function']} \nQuery: $sql\n");
     */
     $this->checkError($msg . ' Query Failed: ' . $sql, $dieOnError);
     if ($autofree) {
         $this->lastResult[] =& $result;
     }
     return $result;
 }
Esempio n. 3
0
 /**
  * @see MysqlManager::query()
  */
 public function query($sql, $dieOnError = false, $msg = '', $suppress = false, $autofree = false)
 {
     static $queryMD5 = array();
     parent::countQuery($sql);
     //$GLOBALS['log']->info('Query:' . $sql);
     $this->checkConnection();
     //$this->freeResult();
     $this->query_time = microtime(true);
     $this->lastsql = $sql;
     if ($suppress == true) {
     } else {
         $result = mysqli_query($this->database, $sql);
     }
     $md5 = md5($sql);
     if (empty($queryMD5[$md5])) {
         $queryMD5[$md5] = true;
     }
     $this->lastmysqlrow = -1;
     $this->query_time = microtime(true) - $this->query_time;
     //$GLOBALS['log']->info('Query Execution Time:'.$this->query_time);
     //$this->checkError($msg.' Query Failed:' . $sql . '::', $dieOnError);
     $this->checkError($msg . ' Failed:::', 'SQL');
     if ($autofree) {
         $this->lastResult[] =& $result;
     }
     return $result;
 }