web/app/db.php
/**
	 * Basic query. See docs for more details.
	 * @param string $query
	 * @return int number of rows
	 */
Basic query. See docs for more details.
@param string $query
@return int number of rows
Basic query . See docs for more details . @param string $query @return int number of rows
function query($query) {
		if ( function_exists('apply_filters') )
			$query = apply_filters('query', $query);
		$return_val = 0;
		$this->flush();
		$this->func_call = "\$db->query(\"$query\")";
		$this->last_query = $query;
		if ( preg_match('/^\s*SELECT\s+FOUND_ROWS(\s*)/i', $query) && ($this->last_found_rows_result instanceof mysqli_result) ) {
			$this->result = $this->last_found_rows_result;
			$elapsed = 0;
		} else {
			$this->dbh = $this->db_connect( $query );
			if ( !( $this->dbh instanceof mysqli ) )
				return false;
			$this->timer_start();
			$this->result = mysqli_query( $this->dbh, $query );
			$elapsed = $this->timer_stop();
			++$this->num_queries;
			if ( preg_match('/^\s*SELECT\s+SQL_CALC_FOUND_ROWS\s/i', $query) ) {
				if ( false === strpos($query, "NO_SELECT_FOUND_ROWS") ) {
					$this->timer_start();
					$this->last_found_rows_result = mysqli_query( $this->dbh, "SELECT FOUND_ROWS()" );
					$elapsed += $this->timer_stop();
					++$this->num_queries;
					$query .= "; SELECT FOUND_ROWS()";
				}
			} else {
				$this->last_found_rows_result = null;
			}
			if ( $this->save_queries ) {
				if ( is_callable($this->save_query_callback) )
					$this->queries[] = call_user_func_array( $this->save_query_callback, array( $query, $elapsed, $this->save_backtrace ? debug_backtrace( false ) : null, &$this ) );
				else
					$this->queries[] = array( $query, $elapsed, $this->get_caller() );
			}
		}
		if ( $this->last_error = mysqli_error($this->dbh) ) {
			$this->print_error($this->last_error);
			return false;
		}
		if ( preg_match("/^\\s*(insert|delete|update|replace|alter) /i",$query) ) {
			$this->rows_affected = mysqli_affected_rows($this->dbh);
			if ( preg_match("/^\\s*(insert|replace) /i",$query) ) {
				$this->insert_id = mysqli_insert_id($this->dbh);
			}
			$return_val = $this->rows_affected;
		} else {
			$i = 0;
			$this->col_info = array();
			while ($i < @mysqli_num_fields($this->result)) {
				$this->col_info[$i] = @mysqli_fetch_field($this->result);
				$i++;
			}
			$num_rows = 0;
			$this->last_result = array();
			while ( $row = @mysqli_fetch_object($this->result) ) {
				$this->last_result[$num_rows] = $row;
				$num_rows++;
			}
			@mysqli_free_result($this->result);
			$this->num_rows = $num_rows;
			$return_val = $this->num_rows;
		}
		return $return_val;
	}
function query ( $ query ) { if ( function_exists ( 'apply_filters' ) ) $ query = apply_filters ( 'query' , $ query ) ; $ return_val = 0 ; $ this -> flush ( ) ; $ this -> func_call = " \$ db->query( \" $ query \" ) " ; $ this -> last_query = $ query ; if ( preg_match ( '/^\s*SELECT\s+FOUND_ROWS(\s*)/i' , $ query ) && ( $ this -> last_found_rows_result instanceof mysqli_result ) ) { $ this -> result = $ this -> last_found_rows_result ; $ elapsed = 0 ; } else { $ this -> dbh = $ this -> db_connect ( $ query ) ; if ( ! ( $ this -> dbh instanceof mysqli ) ) return false ; $ this -> timer_start ( ) ; $ this -> result = mysqli_query ( $ this -> dbh , $ query ) ; $ elapsed = $ this -> timer_stop ( ) ; ++ $ this -> num_queries ; if ( preg_match ( '/^\s*SELECT\s+SQL_CALC_FOUND_ROWS\s/i' , $ query ) ) { if ( false === strpos ( $ query , " NO_SELECT_FOUND_ROWS " ) ) { $ this -> timer_start ( ) ; $ this -> last_found_rows_result = mysqli_query ( $ this -> dbh , " SELECT FOUND_ROWS() " ) ; $ elapsed += $ this -> timer_stop ( ) ; ++ $ this -> num_queries ; $ query .= " ; SELECT FOUND_ROWS() " ; } } else { $ this -> last_found_rows_result = null ; } if ( $ this -> save_queries ) { if ( is_callable ( $ this -> save_query_callback ) ) $ this -> queries [ ] = call_user_func_array ( $ this -> save_query_callback , array ( $ query , $ elapsed , $ this -> save_backtrace ? debug_backtrace ( false ) : null , & $ this ) ) ; else $ this -> queries [ ] = array ( $ query , $ elapsed , $ this -> get_caller ( ) ) ; } } if ( $ this -> last_error = mysqli_error ( $ this -> dbh ) ) { $ this -> print_error ( $ this -> last_error ) ; return false ; } if ( preg_match ( " /^ \\ s*(insert|delete|update|replace|alter) /i " , $ query ) ) { $ this -> rows_affected = mysqli_affected_rows ( $ this -> dbh ) ; if ( preg_match ( " /^ \\ s*(insert|replace) /i " , $ query ) ) { $ this -> insert_id = mysqli_insert_id ( $ this -> dbh ) ; } $ return_val = $ this -> rows_affected ; } else { $ i = 0 ; $ this -> col_info = array ( ) ; while ( $ i < @ mysqli_num_fields ( $ this -> result ) ) { $ this -> col_info [ $ i ] = @ mysqli_fetch_field ( $ this -> result ) ; $ i ++ ; } $ num_rows = 0 ; $ this -> last_result = array ( ) ; while ( $ row = @ mysqli_fetch_object ( $ this -> result ) ) { $ this -> last_result [ $ num_rows ] = $ row ; $ num_rows ++ ; } @ mysqli_free_result ( $ this -> result ) ; $ this -> num_rows = $ num_rows ; $ return_val = $ this -> num_rows ; } return $ return_val ; }
Basic query.
Basic query .
// some queries are made before the plugins have been loaded, and thus cannot be filtered with this method // initialise return // Log how the function was called // Keep track of the last query for debug.. // If there is an error then take note of it // Take note of the insert_id // Return number of rows affected // Log number of rows the query returned // Return number of rows selected