[ Index ]

WordPress Cross Reference

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: 1760 lines (48 kb)
Included or required: 2 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

wpdb:: (46 methods):
  __construct()
  __destruct()
  __get()
  __set()
  __isset()
  __unset()
  init_charset()
  set_charset()
  set_prefix()
  set_blog_id()
  get_blog_prefix()
  tables()
  select()
  _weak_escape()
  _real_escape()
  _escape()
  escape()
  escape_by_ref()
  prepare()
  print_error()
  show_errors()
  hide_errors()
  suppress_errors()
  flush()
  db_connect()
  query()
  insert()
  replace()
  _insert_replace_helper()
  update()
  delete()
  get_var()
  get_row()
  get_col()
  get_results()
  load_col_info()
  get_col_info()
  timer_start()
  timer_stop()
  bail()
  check_database_version()
  supports_collation()
  get_charset_collate()
  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 to your class. The wpdb class will still be included,
so you can extend it or simply use your own.

__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 true

__get( $name )   X-Ref
PHP5 style magic getter, used to lazy-load expensive data.

param: string $name The private member to get, and optionally process
return: mixed The private member

__set( $name, $value )   X-Ref
Magic function, for backwards compatibility

param: string $name  The private member to set
param: mixed  $value The value to set

__isset( $name )   X-Ref
Magic function, for backwards compatibility

param: string $name  The private member to check
return: bool If the member is set or not

__unset( $name )   X-Ref
Magic function, for backwards compatibility

param: string $name  The private member to unset

init_charset()   X-Ref
Set $this->charset and $this->collate


set_charset( $dbh, $charset = null, $collate = null )   X-Ref
Sets the connection's character set.

param: resource $dbh     The resource given by mysql_connect
param: string   $charset The character set (optional)
param: string   $collate The collation (optional)

set_prefix( $prefix, $set_table_names = true )   X-Ref
Sets the table prefix for the WordPress tables.

param: string $prefix Alphanumeric name for the new prefix.
param: bool $set_table_names Optional. Whether the table names, e.g. wpdb::$posts, should be updated or not.
return: string|WP_Error Old prefix or WP_Error on error

set_blog_id( $blog_id, $site_id = 0 )   X-Ref
Sets blog id.

param: int $blog_id
param: int $site_id Optional.
return: string previous blog id

get_blog_prefix( $blog_id = null )   X-Ref
Gets blog prefix.

param: int $blog_id Optional.
return: string Blog prefix.

tables( $scope = 'all', $prefix = true, $blog_id = 0 )   X-Ref
Returns an array of WordPress tables.

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

The scope argument can take one of the following:

'all' - returns 'all' and 'global' tables. No old tables are returned.
'blog' - returns the blog-level tables for the queried blog.
'global' - returns the global tables for the installation, returning multisite tables only if running multisite.
'ms_global' - returns the multisite global tables, regardless if current installation is multisite.
'old' - returns tables which are deprecated.

param: string $scope Optional. Can be all, global, ms_global, blog, or old tables. Defaults to all.
param: bool $prefix Optional. Whether to include table prefixes. Default true. If blog
param: int $blog_id Optional. The blog_id to prefix. Defaults to wpdb::$blogid. Used only when prefix is requested.
return: array Table names. When a prefix is requested, the key is the unprefixed table name.

select( $db, $dbh = null )   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
param: resource $dbh Optional link identifier.
return: null Always null.

_weak_escape( $string )   X-Ref
Do not use, deprecated.

Use esc_sql() or wpdb::prepare() instead.

param: string $string
return: string

_real_escape( $string )   X-Ref
Real escape, using mysql_real_escape_string()

param: string $string to escape
return: string escaped

_escape( $data )   X-Ref
Escape data. Works on arrays.

param: string|array $data
return: string|array escaped

escape( $data )   X-Ref
Do not use, deprecated.

Use esc_sql() or wpdb::prepare() instead.

param: mixed $data
return: mixed

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

param: string $string to escape
return: void

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

The following directives can be used in the query format string:
%d (integer)
%f (float)
%s (string)
%% (literal percentage sign - no argument needed)

All of %d, %f, and %s are to be left unquoted in the query string and they need an argument passed for them.
Literals (%) as parts of the query must be properly written as %%.

This function only supports a small subset of the sprintf syntax; it only supports %d (integer), %f (float), and %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 )
wpdb::prepare( "SELECT DATE_FORMAT(`field`, '%%c') FROM `table` WHERE `column` = %s", 'foo' );
</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
param: mixed $args,... further variables to substitute into the query's placeholders if being called like
return: null|false|string Sanitized query string, null if there is no query, false if there is an error and 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.

By default database errors are not shown.

return: bool Whether showing of errors was active

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

By default database errors are suppressed, with a simple
call to this function they can be enabled.

param: bool $suppress Optional. New value. Defaults to true.
return: bool Old value

flush()   X-Ref
Kill cached query results.

return: void

db_connect()   X-Ref
Connect to and select database


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 Database 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' => 'bar' ) )
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.
return: int|false The number of rows inserted, or false on error.

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

<code>
wpdb::replace( 'table', array( 'column' => 'foo', 'field' => 'bar' ) )
wpdb::replace( '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.
return: int|false The number of rows affected, or false on error.

_insert_replace_helper( $table, $data, $format = null, $type = 'INSERT' )   X-Ref
Helper function for insert and replace.

Runs an insert or replace query based on $type argument.

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.
param: string $type Optional. What type of operation is this? INSERT or REPLACE. Defaults to INSERT.
return: int|false The number of rows affected, 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' => 'bar' ), array( 'ID' => 1 ) )
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.
param: array|string $where_format 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', '%f', '%s' (integer, float, string). If omitted, all values in $where will be treated as strings.
return: int|false The number of rows updated, or false on error.

delete( $table, $where, $where_format = null )   X-Ref
Delete a row in the table

<code>
wpdb::delete( 'table', array( 'ID' => 1 ) )
wpdb::delete( 'table', array( 'ID' => 1 ), array( '%d' ) )
</code>

param: string $table table name
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 $where_format 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', '%f', '%s' (integer, float, string). If omitted, all values in $where will be treated as strings unless otherwise specified in wpdb::$field_types.
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 Optional. SQL query. Defaults to 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|null Database query result (as string), or null on failure

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, ...),
param: int $y Optional. Row to return. Indexed from 0.
return: mixed Database query result in format specified by $output or null on failure

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 Optional. SQL query. Defaults to previous query.
param: int $x Optional. 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. Any 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.
return: mixed Database query results

load_col_info()   X-Ref
Load the column metadata from the last query.


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

param: string $info_type Optional. 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 Optional. 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: float Total time spent on the query, in seconds

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 false.

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 MySQL database is at least the required minimum version.

return: WP_Error

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

Called when WordPress is generating the table scheme.

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

get_charset_collate()   X-Ref
The database character collate.

return: string The database character collate.

has_cap( $db_cap )   X-Ref
Determine if a database supports a particular feature.

param: string $db_cap The feature to check for.
return: bool

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

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.

return: false|string false on failure, version number on success



Generated: Tue Mar 25 01:41:18 2014 WordPress honlapkészítés: online1.hu