PHP5 style constructor
Grabs the arguments, calls bpdb::_init() and then connects to the database
void
__construct
()
Redefined in descendants as:
PHP4 style constructor
unknown
BPDB
()
PHP5 style destructor, registered as shutdown function in PHP4
bool
__destruct
()
Wraps errors in a nice header and footer and dies.
Will not die if bpdb::$show_errors is true
false|void
bail
(string $message)
Whether or not MySQL database is at least the required minimum version.
WP_Error
check_database_version
([
$dbh_or_table =
false])
Figure out which database server should handle the query, and connect to it.
resource
&db_connect
([string $query = ''])
Redefined in descendants as:
Connects to the database server and selects a database
void|bool
db_connect_host
(array $args)
-
array
$args: args name => string DB name (required) user => string DB user (optional: false) password => string DB user password (optional: false) host => string DB hostname (optional: 'localhost') charset => string DB default charset. Used in a SET NAMES query. (optional) collate => string DB default collation. If charset supplied, optionally added to the SET NAMES query (optional)
The database version number
false|string
db_version
([false|string|resource $dbh_or_table = false])
-
false|string|resource
$dbh_or_table: 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.
Escapes content for insertion into the database using addslashes(), for security
string
escape
(string|array $data)
Escapes content by reference for insertion into the database, for security
void
escape_by_ref
( &$string, string $s)
Escapes array recursively for insertion into the database, for security
void
escape_deep
(array $array)
Kill cached query results.
void
flush
()
Retrieve the name of the function that called bpdb.
Requires PHP 4.3 and searches up the list of functions until it reaches the one that would most logically had called this method.
string
get_caller
()
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.
array
get_col
([string|null $query = null], [int $x = 0])
-
string|null
$query: SQL query. If null, use the result from the previous query.
-
int
$x: Column to return. Indexed from 0.
Retrieve column metadata from the last query.
mixed
get_col_info
([string $info_type = 'name'], [int $col_offset = -1])
-
string
$info_type: one of name, table, def, max_length, not_null, primary_key, multiple_key, unique_key, numeric, blob, type, unsigned, zerofill
-
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
Get SQL/DB error
void
get_error
([string $str = ''])
-
string
$str: Error string
Retrieve an entire SQL result set from the database (i.e., many rows)
Executes a SQL query and returns the entire SQL result.
mixed
get_results
([string $query = null], [string $output = OBJECT])
-
string
$query: SQL query.
-
string
$output: (optional) ane of ARRAY_A | ARRAY_N | OBJECT | OBJECT_K | ARRAY_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 and ARRAY_K, return an associative array of row objects keyed by the value of each row's first column's value. Duplicate keys are discarded.
Retrieve one row from the database.
Executes a SQL query and returns the row from the SQL result.
mixed
get_row
([string|null $query = null], [string $output = OBJECT], [int $y = 0])
-
string|null
$query: SQL query.
-
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.
-
int
$y: (optional) Row to return. Indexed from 0.
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.
string
get_var
([string|null $query = null], [int $x = 0], [int $y = 0])
-
string|null
$query: SQL query. If null, use the result from the previous query.
-
int
$x: (optional) Column of value to return. Indexed from 0.
-
int
$y: (optional) Row of value to return. Indexed from 0.
Generic function to determine if a database supports a particular feature
bool
has_cap
(string $db_cap, [false|string|resource $dbh_or_table = false])
-
string
$db_cap: the feature
-
false|string|resource
$dbh_or_table: 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.
Disables showing of database errors.
bool
hide_errors
()
Insert a row into a table.
wpdb::insert( 'table', array( 'column' => 'foo', 'field' => 1337 ), array( '%s', '%d' ) )
int|false
insert
(string $table, array $data, [array|string $format = null])
-
string
$table: table name
-
array
$data: Data to insert (in column => value pairs). Both $data columns and $data values should be "raw" (neither should be SQL escaped).
-
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.
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 sprintf() or like vsprintf().
Both %d and %s should be left unquoted in the query string.
wpdb::prepare( "SELECT * FROM `table` WHERE `column` = %s AND `field` = %d", "foo", 1337 )
null|string
prepare
([string $query = null], array|mixed $args, mixed $args,...)
-
string
$query: Query statement with sprintf()-like placeholders
-
array|mixed
$args: The array of variables to substitute into the query's placeholders if being called like vsprintf(), or the first variable to substitute into the query's placeholders if being called like sprintf().
-
mixed
$args,...: further variables to substitute into the query's placeholders if being called like sprintf().
Print SQL/DB error.
bool
print_error
([string $str = ''])
-
string
$str: The error to display
Perform a MySQL database query, using current database connection.
More information can be found on the codex page.
int|false
query
(string $query, [ $use_current = false])
-
string
$query
-
$use_current
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.
bool
select
(string $db, &$dbh)
-
string
$db: MySQL database name
-
&$dbh
Sets the table prefix for the WordPress tables.
string
set_prefix
(string $prefix, [false|array $tables = false])
-
string
$prefix: prefix
-
false|array
$tables: tables (optional: false) table identifiers are array keys array values empty: set prefix: array( 'posts' => false, 'users' => false, ... ) string: set to that array value: array( 'posts' => 'my_posts', 'users' => 'my_users' ) OR array values (with numeric keys): array( 'posts', 'users', ... )
Redefined in descendants as:
Enables showing of database errors.
This function should be used only to enable showing of errors. bpdb::hide_errors() should be used instead for hiding of errors. However, this function can be used to enable and disable showing of database errors.
bool
show_errors
([bool $show = true])
-
bool
$show: Whether to show or hide errors
Whether of not the database supports collation.
Called when BackPress is generating the table scheme.
bool
supports_collation
()
Whether to suppress database errors.
bool
suppress_errors
([bool $suppress = true])
Starts the timer, for debugging purposes.
true
timer_start
()
Stops the debugging timer.
int
timer_stop
()
Update a row in the table
wpdb::update( 'table', array( 'column' => 'foo', 'field' => 1337 ), array( 'ID' => 1 ), array( '%s', '%d' ), array( '%d' ) )
int|false
update
(string $table, array $data, array $where, [array|string $format = null], [ $where_format = null], array|string $format_where)
-
string
$table: table name
-
array
$data: Data to update (in column => value pairs). Both $data columns and $data values should be "raw" (neither should be SQL escaped).
-
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".
-
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.
-
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.
-
$where_format
Initialises the class variables based on provided arguments
array
_init
(array $args)
-
array
$args: The provided connection settings
void
_real_escape
( $string)
void
_weak_escape
( $string)