wpdb
- Since
- 0.71
- Source
wp-includes/class-wpdb.php:54
WordPress database access abstraction class.
Description
This class is used to interact with a database without needing to use raw SQL statements.
By default, WordPress uses this class to instantiate the global $wpdb object, providing access to the WordPress database.
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.
Compatibility
- WordPress
- since 0.71
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0).
Hooks and filters fired · 5
Every hook that fires from inside wpdb, in the order it appears in the class, grouped by the method that fires it.
wpdb::set_sql_mode()
- apply_filters( incompatible_sql_modes )filter line 982
wpdb::query()
- apply_filters( query )filter line 2228
wpdb::log_query()
- apply_filters( log_query_custom_data )filter line 2393
wpdb::get_table_charset()
- apply_filters( pre_get_table_charset )filter line 3216
wpdb::get_col_charset()
- apply_filters( pre_get_col_charset )filter line 3316
Properties · 62
$show_errorsboolpublic- Whether to show SQL/DB errors.
$suppress_errorsboolpublic- Whether to suppress errors during the DB bootstrapping. Default false.
$last_errorstringpublic- The error encountered during the last query.
$num_queriesintpublic- The number of queries made.
$num_rowsintpublic- Count of rows returned by the last query.
$rows_affectedintpublic- Count of rows affected by the last query.
$insert_idintpublic- The ID generated for an AUTO_INCREMENT column by the last query (usually INSERT).
$last_querystringpublic- The last query made.
$last_resultstdClass[]|nullpublic- Results of the last query.
$resultmysqli_result|bool|nullprotected- Database query result.
$col_metaarrayprotected- Cached column info, for confidence checking data before inserting.
$table_charsetstring[]protected- Calculated character sets keyed by table name.
$check_current_queryboolprotected- Whether text fields in the current query need to be confidence checked.
$checking_collationboolprivate- Flag to ensure we don't run into recursion problems when checking the collation.
$col_infoarrayprotected- Saved info on the table column.
$queriesarray[]public- Log of queries that were executed, for debugging purposes.
$reconnect_retriesintprotected- The number of times to retry reconnecting before dying. Default 5.
$prefixstringpublic- WordPress table prefix.
$base_prefixstringpublic- WordPress base table prefix.
$readyboolpublic- Whether the database queries are ready to start executing.
$blogidintpublic- Blog ID.
$siteidintpublic- Site ID.
$tablesstring[]public- List of WordPress per-site tables.
$old_tablesstring[]public- List of deprecated WordPress tables.
$global_tablesstring[]public- List of WordPress global tables.
$ms_global_tablesstring[]public- List of Multisite global tables.
$old_ms_global_tablesstring[]public- List of deprecated WordPress Multisite global tables.
$commentsstringpublic- WordPress Comments table.
$commentmetastringpublic- WordPress Comment Metadata table.
$linksstringpublic- WordPress Links table.
$optionsstringpublic- WordPress Options table.
$postmetastringpublic- WordPress Post Metadata table.
$postsstringpublic- WordPress Posts table.
$termsstringpublic- WordPress Terms table.
$term_relationshipsstringpublic- WordPress Term Relationships table.
$term_taxonomystringpublic- WordPress Term Taxonomy table.
$termmetastringpublic- WordPress Term Meta table.
$usermetastringpublic- WordPress User Metadata table.
$usersstringpublic- WordPress Users table.
$blogsstringpublic- Multisite Blogs table.
$blogmetastringpublic- Multisite Blog Metadata table.
$registration_logstringpublic- Multisite Registration Log table.
$signupsstringpublic- Multisite Signups table.
$sitestringpublic- Multisite Sites table.
$sitecategoriesstringpublic- Multisite Sitewide Terms table.
$sitemetastringpublic- Multisite Site Metadata table.
$field_typesarraypublic- Format specifiers for DB columns.
$charsetstringpublic- Database table columns charset.
$collatestringpublic- Database table columns collate.
$dbuserstringprotected- Database Username.
$dbpasswordstringprotected- Database Password.
$dbnamestringprotected- Database Name.
$dbhoststringprotected- Database Host.
$dbhmysqli|false|nullprotected- Database handle.
$func_callstringpublic- A textual description of the last query/get_row/get_var call.
$is_mysqlboolpublic- Whether MySQL is used as the database engine.
$incompatible_modesstring[]protected- A list of incompatible SQL modes.
$allow_unsafe_unquoted_parametersboolprivate- Backward compatibility, where wpdb::prepare() has not quoted formatted/argnum placeholders.
$use_mysqliboolprivate- Whether to use the mysqli extension over mysql. This is no longer used as the mysql extension is no longer supported.
$has_connectedboolprivate- Whether we've managed to successfully connect at some point.
$time_startfloatpublic- Time when the last query was performed.
$errorWP_Error|stringpublic- The last SQL error that was encountered.
Methods · 72
- __construct()Connects to the database server and selects a database.
- __get()Makes private properties readable for backward compatibility.
- __set()Makes private properties settable for backward compatibility.
- __isset()Makes private properties check-able for backward compatibility.
- __unset()Makes private properties un-settable for backward compatibility.
- init_charset()Sets $this->charset and $this->collate.
- determine_charset()Determines the best charset and collation to use given a charset and collation.
- set_charset()Sets the connection's character set.
- set_sql_mode()Changes the current SQL mode, and ensures its WordPress compatibility.
- set_prefix()Sets the table prefix for the WordPress tables.
- set_blog_id()Sets blog ID.
- get_blog_prefix()Gets blog prefix.
- tables()Returns an array of WordPress tables.
- select()Selects a database using the current or provided database connection.
- _weak_escape()Do not use, deprecated.
- _real_escape()Real escape using mysqli_real_escape_string().
- _escape()Escapes data. Works on arrays.
- escape()Do not use, deprecated.
- escape_by_ref()Escapes content by reference for insertion into the database, for security.
- quote_identifier()Quotes an identifier for a MySQL database, e.g. table/field names.
- _escape_identifier_value()Escapes an identifier value without adding the surrounding quotes.
- prepare()Prepares a SQL query for safe execution.
- esc_like()First half of escaping for `LIKE` special characters `%` and `_` before preparing for SQL.
- print_error()Prints SQL/DB error.
- show_errors()Enables showing of database errors.
- hide_errors()Disables showing of database errors.
- suppress_errors()Enables or disables suppressing of database errors.
- flush()Kills cached query results.
- db_connect()Connects to and selects database.
- parse_db_host()Parses the DB_HOST setting to interpret it for mysqli_real_connect().
- check_connection()Checks that the connection to the database is still up. If not, try to reconnect.
- query()Performs a database query, using current database connection.
- _do_query()Internal function to perform the mysqli_query() call.
- log_query()Logs query data.
- placeholder_escape()Generates and returns a placeholder escape string for use in queries returned by ::prepare().
- add_placeholder_escape()Adds a placeholder escape string, to escape anything that resembles a printf() placeholder.
- remove_placeholder_escape()Removes the placeholder escape strings from a query.
- insert()Inserts a row into the table.
- replace()Replaces a row in the table or inserts it if it does not exist, based on a PRIMARY KEY or a UNIQUE index.
- _insert_replace_helper()Helper function for insert and replace.
- update()Updates a row in the table.
- delete()Deletes a row in the table.
- process_fields()Processes arrays of field/value pairs and field formats.
- process_field_formats()Prepares arrays of value/format pairs as passed to wpdb CRUD methods.
- process_field_charsets()Adds field charsets to field/value/format arrays generated by wpdb::process_field_formats().
- process_field_lengths()For string fields, records the maximum string length that field can safely save.
- get_var()Retrieves one value from the database.
- get_row()Retrieves one row from the database.
- get_col()Retrieves one column from the database.
- get_results()Retrieves an entire SQL result set from the database (i.e., many rows).
- get_table_charset()Retrieves the character set for the given table.
- get_col_charset()Retrieves the character set for the given column.
- get_col_length()Retrieves the maximum string length allowed in a given column.
- check_ascii()Checks if a string is ASCII.
- check_safe_collation()Checks if the query is accessing a collation considered safe on the current version of MySQL.
- strip_invalid_text()Strips any invalid characters based on value/charset pairs.
- strip_invalid_text_from_query()Strips any invalid characters from the query.
- strip_invalid_text_for_column()Strips any invalid characters from the string for a given table and column.
- get_table_from_query()Finds the first table name referenced in a query.
- load_col_info()Loads the column metadata from the last query.
- get_col_info()Retrieves column metadata from the last query.
- timer_start()Starts the timer, for debugging purposes.
- timer_stop()Stops the debugging timer.
- bail()Wraps errors in a nice header and footer and dies.
- close()Closes the current database connection.
- check_database_version()Determines whether MySQL database is at least the required minimum version.
- supports_collation()Determines whether the database supports collation.
- get_charset_collate()Retrieves the database character collate.
- has_cap()Determines whether the database or WPDB supports a particular feature.
- get_caller()Retrieves a comma-separated list of the names of the functions that called wpdb.
- db_version()Retrieves the database server version.
- db_server_info()Returns the version of the MySQL server.
Source code
#[AllowDynamicProperties]class wpdb { /** * Whether to show SQL/DB errors. * * Default is to show errors if both WP_DEBUG and WP_DEBUG_DISPLAY evaluate to true. * * @since 0.71 * * @var bool */ public $show_errors = false; /** * Whether to suppress errors during the DB bootstrapping. Default false. * * @since 2.5.0 * * @var bool */ public $suppress_errors = false; /** * The error encountered during the last query. * * @since 2.5.0 * * @var string */ public $last_error = ''; /** * The number of queries made. * * @since 1.2.0 * * @var int */ public $num_queries = 0; /** * Count of rows returned by the last query. * * @since 0.71 * * @var int */ public $num_rows = 0; /** * Count of rows affected by the last query. * * @since 0.71 * * @var int */ public $rows_affected = 0; /** * The ID generated for an AUTO_INCREMENT column by the last query (usually INSERT). * * @since 0.71 * * @var int */ public $insert_id = 0; /** * The last query made. * * @since 0.71 * * @var string */ public $last_query; /** * Results of the last query. *Changelog
Introduced in 0.71. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.8.8 tag, from
src/wp-includes/class-wpdb.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.