function query($query, $QT = NULL) { if (!self::$dbh) { self::connect(); } // filter the query, if filters are available // NOTE: some queries are made before the plugins have been loaded, and thus cannot be filtered with this method $query = str_replace('#iCMS@__', DB_PREFIX, $query); // initialise return $return_val = 0; self::flush(); // Log how the function was called self::$func_call = __CLASS__ . "::query(\"{$query}\")"; // Keep track of the last query for debug.. self::$last_query = $query; // Perform the query via std mysql_query function.. if (SAVEQUERIES) { self::timer_start(); } self::$result = mysql_query($query, self::$dbh); self::$num_queries++; if (SAVEQUERIES) { self::$queries[] = array($query, self::timer_stop()); } // If there is an error then take note of it.. if (self::$last_error = mysql_error(self::$dbh)) { self::print_error(); return false; } $QH = strtoupper(substr($query, 0, strpos($query, ' '))); if (in_array($QH, array("INSERT", "DELETE", "UPDATE", "REPLACE"))) { $rows_affected = mysql_affected_rows(self::$dbh); // Take note of the insert_id if (in_array($QH, array("INSERT", "REPLACE"))) { self::$insert_id = mysql_insert_id(self::$dbh); } // Return number of rows affected $return_val = $rows_affected; } else { if ($QT == "field") { $i = 0; while ($i < @mysql_num_fields(self::$result)) { self::$col_info[$i] = mysql_fetch_field(self::$result); $i++; } } else { $num_rows = 0; while ($row = @mysql_fetch_object(self::$result)) { self::$last_result[$num_rows] = $row; $num_rows++; } // Log number of rows the query returned self::$num_rows = $num_rows; // Return number of rows selected $return_val = $num_rows; } @mysql_free_result(self::$result); } return $return_val; }