Example #1
0
 /**
  * private function which actually runs a query against Mysql server.
  * also logs some stats like profiling info and error message
  * 
  * @param string $query - a regular SQL query
  * @return mysqli result resource or FALSE on error
  */
 private function rawQuery($query)
 {
     $this->_insertID = null;
     $start = microtime(TRUE);
     $res = mysqli_query($this->conn, $query);
     $insertID = mysqli_insert_id($this->conn);
     if ($insertID) {
         $this->_insertID = $insertID;
     }
     $timer = microtime(TRUE) - $start;
     $this->countQuery++;
     $this->stats[] = array('query' => $query, 'start' => $start, 'timer' => $timer);
     if (AF::showAjaxQuery()) {
         $query = htmlspecialchars("{$query}", ENT_QUOTES);
         $query = str_replace(array("\n", "\r"), "", $query);
         $content = '';
         $contentA = $this->countQuery == 1 ? '$("div.service_info_querys div.ajax").show(); $("div.service_info_querys div.ajax div").html(""); ' : '';
         $content .= '<br>' . $this->countQuery . '. Sql :<b>' . $query . '</b><br>Time: ' . $timer;
         echo '<script> ' . $contentA . '$("div.service_info_querys div.ajax div").append(\'' . $content . '\'); /*count_sql_queries++; $("span#count_sql_queries").html(count_sql_queries)*/</script>';
     }
     if (!$res) {
         $error = mysqli_error($this->conn);
         end($this->stats);
         $key = key($this->stats);
         $this->stats[$key]['error'] = $error;
         $this->cutStats();
         $this->error("{$error}. Full query: [{$query}]");
     }
     $this->cutStats();
     /*
             //temp sql collection
             $s=strtolower(substr(trim($query), 0, 23));
             if($s!='update `users_sessions`')
             {
                 $md5=md5($query);
                 $query=str_replace("'", "\'", $query);
                 $query=str_replace('"', '\"', $query);
                 $type=strtolower(substr(trim($query), 0, 6));
                 $tSql="INSERT INTO `temp_sql_stat` SET `type`='{$type}', `md5`='{$md5}', `sql`='{$query}', `request_url`='{$_SERVER['REQUEST_URI']}'";
                 mysqli_query($this->conn, $tSql);
             }
     */
     //file_put_contents('/home/limejuic/public_html/lj3/sql_log.log', $query."\n --------- \n", FILE_APPEND);
     return $res;
 }