Property | Type | Description | |
---|---|---|---|
$base_prefix | string | WordPress base table prefix. | |
$blog_versions | string | Multisite Blog Versions table | |
$blogid | integer | {@internal Missing Description}} | |
$blogs | string | Multisite Blogs table | |
$charset | string | Database table columns charset | |
$collate | string | Database table columns collate | |
$commentmeta | string | WordPress Comment Metadata table | |
$comments | string | WordPress Comments table | |
$field_types | array | Keys are column names, values are format types: 'ID' => '%d' | |
$func_call | string | A textual description of the last query/get_row/get_var call | |
$global_tables | array | List of WordPress global tables | |
$insert_id | integer | The ID generated for an AUTO_INCREMENT column by the previous query (usually INSERT). | |
$is_mysql | boolean | Set in WPDB::db_connect() to true, by default. This is used when checking against the required MySQL version for WordPress. Normally, a replacement database drop-in (db.php) will skip these checks, but setting this to true will force the checks to occur. | |
$last_error | string | The last error during query. | |
$last_query | array | Last query made | |
$last_result | array | null | Results of the last query made | |
$links | string | WordPress Links table | |
$ms_global_tables | array | List of Multisite global tables | |
$num_queries | integer | Amount of queries made | |
$num_rows | integer | Count of rows returned by previous query | |
$old_tables | array | categories, post2cat, and link2cat were deprecated in 2.3.0, db version 5539 | |
$options | string | WordPress Options table | |
$postmeta | string | WordPress Post Metadata table | |
$posts | string | WordPress Posts table | |
$prefix | string | You can set this to have multiple WordPress installations in a single database. The second reason is for possible security precautions. | |
$queries | array | Saved queries that were executed | |
$ready | boolean | Whether the database queries are ready to start executing. | |
$registration_log | string | Multisite Registration Log table | |
$rows_affected | integer | Count of affected rows by previous query | |
$show_errors | boolean | Default behavior is to show errors if both WP_DEBUG and WP_DEBUG_DISPLAY evaluated to true. | |
$signups | string | Multisite Signups table | |
$site | string | Multisite Sites table | |
$sitecategories | string | Multisite Sitewide Terms table | |
$siteid | integer | {@internal Missing Description}} | |
$sitemeta | string | Multisite Site Metadata table | |
$suppress_errors | boolean | Whether to suppress errors during the DB bootstrapping. | |
$tables | array | List of WordPress per-blog tables | |
$term_relationships | string | WordPress Term Relationships table | |
$term_taxonomy | string | WordPress Term Taxonomy table | |
$terms | string | WordPress Terms table | |
$usermeta | string | WordPress User Metadata table | |
$users | string | WordPress Users table |
Property | Type | Description | |
---|---|---|---|
$col_info | array | Saved info on the table column | |
$dbh | string | mysqli | resource | Database Handle | |
$dbhost | string | Database Host | |
$dbname | string | Database Name | |
$dbpassword | string | Database Password | |
$dbuser | string | Database Username | |
$incompatible_modes | array | A list of incompatible SQL modes. | |
$reconnect_retries | integer | The number of times to retry reconnecting before dying. | |
$result | mixed | MySQL result, which is either a resource or boolean. |
Method | Description | |
---|---|---|
__construct ( string $dbuser, string $dbpassword, string $dbname, string $dbhost ) | Connects to the database server and selects a database | |
__destruct ( ) : boolean | PHP5 style destructor and will run when database object is destroyed. | |
__get ( string $name ) : mixed | PHP5 style magic getter, used to lazy-load expensive data. | |
__isset ( string $name ) : boolean | Magic function, for backwards compatibility. | |
__set ( string $name, mixed $value ) | Magic function, for backwards compatibility. | |
__unset ( string $name ) | Magic function, for backwards compatibility. | |
_escape ( string | array $data ) : string | array | Escape data. Works on arrays. | |
_insert_replace_helper ( string $table, array $data, array | string $format = null, string $type = 'INSERT' ) : integer | false | Helper function for insert and replace. | |
_real_escape ( string $string ) : string | Real escape, using mysqli_real_escape_string() or mysql_real_escape_string() | |
_weak_escape ( string $string ) : string | Do not use, deprecated. | |
bail ( string $message, string $error_code = '500' ) : false | void | Wraps errors in a nice header and footer and dies. | |
check_connection ( boolean $allow_bail = true ) : boolean | Check that the connection to the database is still up. If not, try to reconnect. | |
check_database_version ( ) : WP_Error | Whether MySQL database is at least the required minimum version. | |
db_connect ( boolean $allow_bail = true ) : boolean | Connect to and select database. | |
db_version ( ) : false | string | The database version number. | |
delete ( string $table, array $where, array | string $where_format = null ) : integer | false | Delete a row in the table | |
esc_like ( string $text ) : string | First half of escaping for LIKE special characters % and _ before preparing for MySQL. | |
escape ( mixed $data ) : mixed | Do not use, deprecated. | |
escape_by_ref ( string &$string ) : void | Escapes content by reference for insertion into the database, for security | |
flush ( ) : void | Kill cached query results. | |
get_blog_prefix ( integer $blog_id = null ) : string | Gets blog prefix. | |
get_caller ( ) : string | Retrieve the name of the function that called wpdb. | |
get_charset_collate ( ) : string | The database character collate. | |
get_col ( string | null $query = null, integer $x ) : array | Retrieve one column from the database. | |
get_col_info ( string $info_type = 'name', integer $col_offset ) : mixed | Retrieve column metadata from the last query. | |
get_results ( string $query = null, string $output = OBJECT ) : mixed | Retrieve an entire SQL result set from the database (i.e., many rows) | |
get_row ( string | null $query = null, string $output = OBJECT, integer $y ) : mixed | Retrieve one row from the database. | |
get_var ( string | null $query = null, integer $x, integer $y ) : string | null | Retrieve one variable from the database. | |
has_cap ( string $db_cap ) : boolean | Determine if a database supports a particular feature. | |
hide_errors ( ) : boolean | Disables showing of database errors. | |
init_charset ( ) | Set $this->charset and $this->collate | |
insert ( string $table, array $data, array | string $format = null ) : integer | false | Insert a row into a table. | |
prepare ( string $query, array | mixed $args ) : null | false | string | Prepares a SQL query for safe execution. Uses sprintf()-like syntax. | |
print_error ( string $str = '' ) : boolean | Print SQL/DB error. | |
query ( string $query ) : integer | false | Perform a MySQL database query, using current database connection. | |
replace ( string $table, array $data, array | string $format = null ) : integer | false | Replace a row into a table. | |
select ( string $db, resource $dbh = null ) : null | Selects a database using the current database connection. | |
set_blog_id ( integer $blog_id, integer $site_id ) : string | Sets blog id. | |
set_charset ( resource $dbh, string $charset = null, string $collate = null ) | Sets the connection's character set. | |
set_prefix ( string $prefix, boolean $set_table_names = true ) : string | WP_Error | Sets the table prefix for the WordPress tables. | |
set_sql_mode ( array $modes = [] ) | Change the current SQL mode, and ensure its WordPress compatibility. | |
show_errors ( boolean $show = true ) : boolean | Enables showing of database errors. | |
supports_collation ( ) : boolean | Whether the database supports collation. | |
suppress_errors ( boolean $suppress = true ) : boolean | Whether to suppress database errors. | |
tables ( string $scope = 'all', boolean $prefix = true, integer $blog_id ) : array | Returns an array of WordPress tables. | |
timer_start ( ) : true | Starts the timer, for debugging purposes. | |
timer_stop ( ) : float | Stops the debugging timer. | |
update ( string $table, array $data, array $where, array | string $format = null, array | string $where_format = null ) : integer | false | Update a row in the table |
Method | Description | |
---|---|---|
load_col_info ( ) | Load the column metadata from the last query. |
Method | Description | |
---|---|---|
_do_query ( string $query ) | Internal function to perform the mysql_query() call. |
public __destruct ( ) : boolean | ||
return | boolean | true |
public _insert_replace_helper ( string $table, array $data, array | string $format = null, string $type = 'INSERT' ) : integer | false | ||
$table | string | table name |
$data | array | Data to insert (in column => value pairs). Both $data columns and $data values should be "raw" (neither should be SQL escaped). |
$format | array | string | 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', '%f', '%s' (integer, float, string). If omitted, all values in $data will be treated as strings unless otherwise specified in wpdb::$field_types. |
$type | string | Optional. What type of operation is this? INSERT or REPLACE. Defaults to INSERT. |
return | integer | false | The number of rows affected, or false on error. |
public _real_escape ( string $string ) : string | ||
$string | string | to escape |
return | string | escaped |
public _weak_escape ( string $string ) : string | ||
$string | string | |
return | string |
public check_connection ( boolean $allow_bail = true ) : boolean | ||
$allow_bail | boolean | Optional. Allows the function to bail. Default true. |
return | boolean | True if the connection is up. |
public check_database_version ( ) : WP_Error | ||
return | WP_Error |
public db_connect ( boolean $allow_bail = true ) : boolean | ||
$allow_bail | boolean | Optional. Allows the function to bail. Default true. |
return | boolean | True with a successful connection, false on failure. |
public db_version ( ) : false | string | ||
return | false | string | false on failure, version number on success |
wpdb::delete( 'table', array( 'ID' => 1 ) )
wpdb::delete( 'table', array( 'ID' => 1 ), array( '%d' ) )
public delete ( string $table, array $where, array | string $where_format = null ) : integer | false | ||
$table | string | table name |
$where | array | 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". |
$where_format | array | string | 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 | integer | false | The number of rows updated, or false on error. |
public escape_by_ref ( string &$string ) : void | ||
$string | string | to escape |
return | void |
public get_blog_prefix ( integer $blog_id = null ) : string | ||
$blog_id | integer | Optional. |
return | string | Blog prefix. |
public get_caller ( ) : string | ||
return | string | The name of the calling function |
public get_charset_collate ( ) : string | ||
return | string | The database character collate. |
public get_col_info ( string $info_type = 'name', integer $col_offset ) : mixed | ||
$info_type | string | Optional. Type one of name, table, def, max_length, not_null, primary_key, multiple_key, unique_key, numeric, blob, type, unsigned, zerofill |
$col_offset | integer | 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 |
public get_results ( string $query = null, string $output = OBJECT ) : mixed | ||
$query | string | SQL query. |
$output | string | 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. 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 |
public get_row ( string | null $query = null, string $output = OBJECT, integer $y ) : mixed | ||
$query | string | null | SQL query. |
$output | string | 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. |
$y | integer | Optional. Row to return. Indexed from 0. |
return | mixed | Database query result in format specified by $output or null on failure |
public get_var ( string | null $query = null, integer $x, integer $y ) : string | null | ||
$query | string | null | Optional. SQL query. Defaults to null, use the result from the previous query. |
$x | integer | Optional. Column of value to return. Indexed from 0. |
$y | integer | Optional. Row of value to return. Indexed from 0. |
return | string | null | Database query result (as string), or null on failure |
public hide_errors ( ) : boolean | ||
return | boolean | Whether showing of errors was active |
wpdb::insert( 'table', array( 'column' => 'foo', 'field' => 'bar' ) )
wpdb::insert( 'table', array( 'column' => 'foo', 'field' => 1337 ), array( '%s', '%d' ) )
public insert ( string $table, array $data, array | string $format = null ) : integer | false | ||
$table | string | table name |
$data | array | Data to insert (in column => value pairs). Both $data columns and $data values should be "raw" (neither should be SQL escaped). |
$format | array | string | 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', '%f', '%s' (integer, float, string). If omitted, all values in $data will be treated as strings unless otherwise specified in wpdb::$field_types. |
return | integer | false | The number of rows inserted, or false on error. |
protected load_col_info ( ) |
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' );
public prepare ( string $query, array | mixed $args ) : null | false | string | ||
$query | string | Query statement with sprintf()-like placeholders |
$args | array | mixed | 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()}. |
return | null | false | string | Sanitized query string, null if there is no query, false if there is an error and string if there was something to prepare |
public print_error ( string $str = '' ) : boolean | ||
$str | string | The error to display |
return | boolean | False if the showing of errors is disabled. |
wpdb::replace( 'table', array( 'column' => 'foo', 'field' => 'bar' ) )
wpdb::replace( 'table', array( 'column' => 'foo', 'field' => 1337 ), array( '%s', '%d' ) )
public replace ( string $table, array $data, array | string $format = null ) : integer | false | ||
$table | string | table name |
$data | array | Data to insert (in column => value pairs). Both $data columns and $data values should be "raw" (neither should be SQL escaped). |
$format | array | string | 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', '%f', '%s' (integer, float, string). If omitted, all values in $data will be treated as strings unless otherwise specified in wpdb::$field_types. |
return | integer | false | The number of rows affected, or false on error. |
public set_charset ( resource $dbh, string $charset = null, string $collate = null ) | ||
$dbh | resource | The resource given by mysql_connect |
$charset | string | The character set (optional) |
$collate | string | The collation (optional) |
public set_prefix ( string $prefix, boolean $set_table_names = true ) : string | WP_Error | ||
$prefix | string | Alphanumeric name for the new prefix. |
$set_table_names | boolean | 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 |
public set_sql_mode ( array $modes = [] ) | ||
$modes | array | Optional. A list of SQL modes to set. |
public show_errors ( boolean $show = true ) : boolean | ||
$show | boolean | Whether to show or hide errors |
return | boolean | Old value for showing errors. |
public supports_collation ( ) : boolean | ||
return | boolean | True if collation is supported, false if version does not |
public suppress_errors ( boolean $suppress = true ) : boolean | ||
$suppress | boolean | Optional. New value. Defaults to true. |
return | boolean | Old value |
public tables ( string $scope = 'all', boolean $prefix = true, integer $blog_id ) : array | ||
$scope | string | Optional. Can be all, global, ms_global, blog, or old tables. Defaults to all. |
$prefix | boolean | Optional. Whether to include table prefixes. Default true. If blog prefix is requested, then the custom users and usermeta tables will be mapped. |
$blog_id | integer | 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. |
public timer_start ( ) : true | ||
return | true |
public timer_stop ( ) : float | ||
return | float | Total time spent on the query, in seconds |
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' ) )
public update ( string $table, array $data, array $where, array | string $format = null, array | string $where_format = null ) : integer | false | ||
$table | string | table name |
$data | array | Data to update (in column => value pairs). Both $data columns and $data values should be "raw" (neither should be SQL escaped). |
$where | array | 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". |
$format | array | string | 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', '%f', '%s' (integer, float, string). If omitted, all values in $data will be treated as strings unless otherwise specified in wpdb::$field_types. |
$where_format | array | string | 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 | integer | false | The number of rows updated, or false on error. |
public string $base_prefix | ||
return | string |
public string $blog_versions | ||
return | string |
protected array $col_info | ||
return | array |
public string $commentmeta | ||
return | string |
protected string|mysqli|resource $dbh | ||
return | string | mysqli | resource |
public array $field_types | ||
return | array |
public string $func_call | ||
return | string |
public array $global_tables | ||
return | array |
protected array $incompatible_modes | ||
return | array |
public int $insert_id | ||
return | integer |
public bool $is_mysql | ||
return | boolean |
public array $ms_global_tables | ||
return | array |
public int $num_rows | ||
return | integer |
public array $old_tables | ||
return | array |
public string $prefix | ||
return | string |
public bool $ready | ||
return | boolean |
protected int $reconnect_retries | ||
return | integer |
public string $registration_log | ||
return | string |
protected mixed $result | ||
return | mixed |
public int $rows_affected | ||
return | integer |
public bool $show_errors | ||
return | boolean |
public string $sitecategories | ||
return | string |
public bool $suppress_errors | ||
return | boolean |
public string $term_relationships | ||
return | string |
public string $term_taxonomy | ||
return | string |