[ Index ]

PHP Cross Reference of Wordpress 2.9.1

title

Body

[close]

/wp-includes/ -> wp-db.php (summary)

WordPress DB Class Original code from {@link http://php.justinvincent.com Justin Vincent (justin@visunet.ie)}

File Size: 1141 lines (32 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

wpdb:: (32 methods):
  wpdb()
  __construct()
  __destruct()
  set_prefix()
  select()
  _weak_escape()
  _real_escape()
  _escape()
  escape()
  escape_by_ref()
  prepare()
  print_error()
  show_errors()
  hide_errors()
  suppress_errors()
  flush()
  query()
  insert()
  update()
  get_var()
  get_row()
  get_col()
  get_results()
  get_col_info()
  timer_start()
  timer_stop()
  bail()
  check_database_version()
  supports_collation()
  has_cap()
  get_caller()
  db_version()


Class: wpdb  - X-Ref

WordPress Database Access Abstraction Object

It is possible to replace this class with your own
by setting the $wpdb global variable in wp-content/db.php
file with your class. You can name it wpdb also, since
this file will not be included, if the other file is
available.

wpdb($dbuser, $dbpassword, $dbname, $dbhost)   X-Ref
Connects to the database server and selects a database

PHP4 compatibility layer for calling the PHP5 constructor.

param: string $dbuser MySQL database user
param: string $dbpassword MySQL database password
param: string $dbname MySQL database name
param: string $dbhost MySQL database host

__construct($dbuser, $dbpassword, $dbname, $dbhost)   X-Ref
Connects to the database server and selects a database

PHP5 style constructor for compatibility with PHP5. Does
the actual setting up of the class properties and connection
to the database.

param: string $dbuser MySQL database user
param: string $dbpassword MySQL database password
param: string $dbname MySQL database name
param: string $dbhost MySQL database host

__destruct()   X-Ref
PHP5 style destructor and will run when database object is destroyed.

return: bool Always true

set_prefix($prefix)   X-Ref
Sets the table prefix for the WordPress tables.

Also allows for the CUSTOM_USER_TABLE and CUSTOM_USER_META_TABLE to
override the WordPress users and usersmeta tables that would otherwise be determined by the $prefix.

param: string $prefix Alphanumeric name for the new prefix.
return: string|WP_Error Old prefix or WP_Error on error

select($db)   X-Ref
Selects a database using the current database connection.

The database name will be changed based on the current database
connection. On failure, the execution will bail and display an DB error.

param: string $db MySQL database name
return: null Always null.

_weak_escape($string)   X-Ref
No description

_real_escape($string)   X-Ref
No description

_escape($data)   X-Ref
No description

escape($data)   X-Ref
Escapes content for insertion into the database using addslashes(), for security

param: string|array $data
return: string query safe string

escape_by_ref(&$string)   X-Ref
Escapes content by reference for insertion into the database, for security

param: string $s

prepare($query = null)   X-Ref
Prepares a SQL query for safe execution.  Uses sprintf()-like syntax.

This function only supports a small subset of the sprintf syntax; it only supports %d (decimal number), %s (string).
Does not support sign, padding, alignment, width or precision specifiers.
Does not support argument numbering/swapping.

May be called like {@link http://php.net/sprintf sprintf()} or like {@link http://php.net/vsprintf vsprintf()}.

Both %d and %s should be left unquoted in the query string.

<code>
wpdb::prepare( "SELECT * FROM `table` WHERE `column` = %s AND `field` = %d", "foo", 1337 )
</code>

param: string $query Query statement with sprintf()-like placeholders
param: array|mixed $args The array of variables to substitute into the query's placeholders if being called like {@link http://php.net/vsprintf vsprintf()}, or the first variable to substitute into the query's placeholders if being called like {@link http://php.net/sprintf sprintf()}.
param: mixed $args,... further variables to substitute into the query's placeholders if being called like {@link http://php.net/sprintf sprintf()}.
return: null|string Sanitized query string

print_error($str = '')   X-Ref
Print SQL/DB error.

param: string $str The error to display
return: bool False if the showing of errors is disabled.

show_errors( $show = true )   X-Ref
Enables showing of database errors.

This function should be used only to enable showing of errors.
wpdb::hide_errors() should be used instead for hiding of errors. However,
this function can be used to enable and disable showing of database
errors.

param: bool $show Whether to show or hide errors
return: bool Old value for showing errors.

hide_errors()   X-Ref
Disables showing of database errors.

return: bool Whether showing of errors was active or not

suppress_errors( $suppress = true )   X-Ref
Whether to suppress database errors.

param: unknown_type $suppress
return: unknown

flush()   X-Ref
Kill cached query results.


query($query)   X-Ref
Perform a MySQL database query, using current database connection.

More information can be found on the codex page.

param: string $query
return: int|false Number of rows affected/selected or false on error

insert($table, $data, $format = null)   X-Ref
Insert a row into a table.

<code>
wpdb::insert( 'table', array( 'column' => 'foo', 'field' => 1337 ), array( '%s', '%d' ) )
</code>

param: string $table table name
param: array $data Data to insert (in column => value pairs).  Both $data columns and $data values should be "raw" (neither should be SQL escaped).
param: array|string $format (optional) An array of formats to be mapped to each of the value in $data.  If string, that format will be used for all of the values in $data.  A format is one of '%d', '%s' (decimal number, string).  If omitted, all values in $data will be treated as strings.
return: int|false The number of rows inserted, or false on error.

update($table, $data, $where, $format = null, $where_format = null)   X-Ref
Update a row in the table

<code>
wpdb::update( 'table', array( 'column' => 'foo', 'field' => 1337 ), array( 'ID' => 1 ), array( '%s', '%d' ), array( '%d' ) )
</code>

param: string $table table name
param: array $data Data to update (in column => value pairs).  Both $data columns and $data values should be "raw" (neither should be SQL escaped).
param: array $where A named array of WHERE clauses (in column => value pairs).  Multiple clauses will be joined with ANDs.  Both $where columns and $where values should be "raw".
param: array|string $format (optional) An array of formats to be mapped to each of the values in $data.  If string, that format will be used for all of the values in $data.  A format is one of '%d', '%s' (decimal number, string).  If omitted, all values in $data will be treated as strings.
param: array|string $format_where (optional) An array of formats to be mapped to each of the values in $where.  If string, that format will be used for all of  the items in $where.  A format is one of '%d', '%s' (decimal number, string).  If omitted, all values in $where will be treated as strings.
return: int|false The number of rows updated, or false on error.

get_var($query=null, $x = 0, $y = 0)   X-Ref
Retrieve one variable from the database.

Executes a SQL query and returns the value from the SQL result.
If the SQL result contains more than one column and/or more than one row, this function returns the value in the column and row specified.
If $query is null, this function returns the value in the specified column and row from the previous SQL result.

param: string|null $query SQL query.  If null, use the result from the previous query.
param: int $x (optional) Column of value to return.  Indexed from 0.
param: int $y (optional) Row of value to return.  Indexed from 0.
return: string Database query result

get_row($query = null, $output = OBJECT, $y = 0)   X-Ref
Retrieve one row from the database.

Executes a SQL query and returns the row from the SQL result.

param: string|null $query SQL query.
param: string $output (optional) one of ARRAY_A | ARRAY_N | OBJECT constants.  Return an associative array (column => value, ...), a numerically indexed array (0 => value, ...) or an object ( ->column = value ), respectively.
param: int $y (optional) Row to return.  Indexed from 0.
return: mixed Database query result in format specifed by $output

get_col($query = null , $x = 0)   X-Ref
Retrieve one column from the database.

Executes a SQL query and returns the column from the SQL result.
If the SQL result contains more than one column, this function returns the column specified.
If $query is null, this function returns the specified column from the previous SQL result.

param: string|null $query SQL query.  If null, use the result from the previous query.
param: int $x Column to return.  Indexed from 0.
return: array Database query result.  Array indexed from 0 by SQL result row number.

get_results($query = null, $output = OBJECT)   X-Ref
Retrieve an entire SQL result set from the database (i.e., many rows)

Executes a SQL query and returns the entire SQL result.

param: string $query SQL query.
param: string $output (optional) ane of ARRAY_A | ARRAY_N | OBJECT | OBJECT_K constants.  With one of the first three, return an array of rows indexed from 0 by SQL result row number.  Each row is an associative array (column => value, ...), a numerically indexed array (0 => value, ...), or an object. ( ->column = value ), respectively.  With OBJECT_K, return an associative array of row objects keyed by the value of each row's first column's value.  Duplicate keys are discarded.
return: mixed Database query results

get_col_info($info_type = 'name', $col_offset = -1)   X-Ref
Retrieve column metadata from the last query.

param: string $info_type one of name, table, def, max_length, not_null, primary_key, multiple_key, unique_key, numeric, blob, type, unsigned, zerofill
param: int $col_offset 0: col name. 1: which table the col's in. 2: col's max length. 3: if the col is numeric. 4: col's type
return: mixed Column Results

timer_start()   X-Ref
Starts the timer, for debugging purposes.

return: true

timer_stop()   X-Ref
Stops the debugging timer.

return: int Total time spent on the query, in milliseconds

bail($message, $error_code = '500')   X-Ref
Wraps errors in a nice header and footer and dies.

Will not die if wpdb::$show_errors is true

param: string $message The Error message
param: string $error_code (optional) A Computer readable string to identify the error.
return: false|void

check_database_version()   X-Ref
Whether or not MySQL database is at least the required minimum version.

return: WP_Error

supports_collation()   X-Ref
Whether of not the database supports collation.

Called when WordPress is generating the table scheme.

return: bool True if collation is supported, false if version does not

has_cap( $db_cap )   X-Ref
Generic function to determine if a database supports a particular feature

param: string $db_cap the feature
param: false|string|resource $dbh_or_table (not implemented) Which database to test.  False = the currently selected database, string = the database containing the specified table, resource = the database corresponding to the specified mysql resource.
return: bool

get_caller()   X-Ref
Retrieve the name of the function that called wpdb.

Requires PHP 4.3 and searches up the list of functions until it reaches
the one that would most logically had called this method.

return: string The name of the calling function

db_version()   X-Ref
The database version number

param: false|string|resource $dbh_or_table (not implemented) Which database to test.  False = the currently selected database, string = the database containing the specified table, resource = the database corresponding to the specified mysql resource.
return: false|string false on failure, version number on success



Generated: Fri Jan 8 00:19:48 2010 Cross-referenced by PHPXref 0.7