wpdb{}WP 0.71AllowDynamicProperties

WordPress database access abstraction class.

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.

Usage

$wpdb = new wpdb();
// use class methods

Methods

  1. public __construct( $dbuser, $dbpassword, $dbname, $dbhost )
  2. public __get( $name )
  3. public __isset( $name )
  4. public __set( $name, $value )
  5. public __unset( $name )
  6. private _do_query( $query )
  7. public _escape( $data )
  8. private _escape_identifier_value( $identifier )
  9. public _insert_replace_helper( $table, $data, $format = null, $type = 'INSERT' )
  10. public _real_escape( $data )
  11. public _weak_escape( $data )
  12. public add_placeholder_escape( $query )
  13. public bail( $message, $error_code = '500' )
  14. protected check_ascii( $input_string )
  15. public check_connection( $allow_bail = true )
  16. public check_database_version()
  17. protected check_safe_collation( $query )
  18. public close()
  19. public db_connect( $allow_bail = true )
  20. public db_server_info()
  21. public db_version()
  22. public delete( $table, $where, $where_format = null )
  23. public determine_charset( $charset, $collate )
  24. public esc_like( $text )
  25. public escape( $data )
  26. public escape_by_ref( &$data )
  27. public flush()
  28. public get_blog_prefix( $blog_id = null )
  29. public get_caller()
  30. public get_charset_collate()
  31. public get_col( $query = null, $x = 0 )
  32. public get_col_charset( $table, $column )
  33. public get_col_info( $info_type = 'name', $col_offset = -1 )
  34. public get_col_length( $table, $column )
  35. public get_results( $query = null, $output = OBJECT )
  36. public get_row( $query = null, $output = OBJECT, $y = 0 )
  37. protected get_table_charset( $table )
  38. protected get_table_from_query( $query )
  39. public get_var( $query = null, $x = 0, $y = 0 )
  40. public has_cap( $db_cap )
  41. public hide_errors()
  42. public init_charset()
  43. public insert( $table, $data, $format = null )
  44. protected load_col_info()
  45. public log_query( $query, $query_time, $query_callstack, $query_start, $query_data )
  46. public parse_db_host( $host )
  47. public placeholder_escape()
  48. public prepare( $query, ...$args )
  49. public print_error( $str = '' )
  50. protected process_field_charsets( $data, $table )
  51. protected process_field_formats( $data, $format )
  52. protected process_field_lengths( $data, $table )
  53. protected process_fields( $table, $data, $format )
  54. public query( $query )
  55. public quote_identifier( $identifier )
  56. public remove_placeholder_escape( $query )
  57. public replace( $table, $data, $format = null )
  58. public select( $db, $dbh = null )
  59. public set_blog_id( $blog_id, $network_id = 0 )
  60. public set_charset( $dbh, $charset = null, $collate = null )
  61. public set_prefix( $prefix, $set_table_names = true )
  62. public set_sql_mode( $modes = array() )
  63. public show_errors( $show = true )
  64. protected strip_invalid_text( $data )
  65. public strip_invalid_text_for_column( $table, $column, $value )
  66. protected strip_invalid_text_from_query( $query )
  67. public supports_collation()
  68. public suppress_errors( $suppress = true )
  69. public tables( $scope = 'all', $prefix = true, $blog_id = 0 )
  70. public timer_start()
  71. public timer_stop()
  72. public update( $table, $data, $where, $format = null, $where_format = null )

Examples

0

#1 Demo of methods usage

global $wpdb;

$done = $wpdb->query( "UPDATE ..." );

// get data

$objects = $wpdb->get_results( "SELECT ..." );

$object = $wpdb->get_row( "SELECT ..." );

$values = $wpdb->get_col( "SELECT ..." );

$var = $wpdb->get_var( "SELECT ..." );

// CRUD data

$done = $wpdb->insert( 'table', [ 'column' => 'foo', 'field' => 'bar' ] );

$done = $wpdb->update( 'table', [ 'column' => $_GET['val'] ], [ 'ID' => 1 ] );

$done = $wpdb->delete( 'table', [ 'ID' => 1 ] );

$done = $wpdb->replace( 'table_name', [ 'ID' => 1, 'column' => $_GET['val'] ] );

Changelog

Since 0.71 Introduced.

wpdb{} code WP 6.5.3

The code is too large. See it here: wp-includes/class-wpdb.php