At the top of the source file wp-includes/wp-db.php I can find the following comment:

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

I was wondering how replacing the wpdb class with a different class would work but I cannot find any file under wp-content/db.php. Is there an error in the documentation?


2 Answers 2


You would create your own dp.php file in the wp-content directory; if you define $wpdb in there, it will replace WordPress's default $wpdb object.

It's not listed on the Pluggable Functions list (not a big surprise, as $wpdb is a class, not a function), but it seems similar in concept.

Also, if you haven't read it yet, I'd recommend you peruse the WPDB Class documentation.


You need to create the file by yourself. This is one of the files that are reffered as "drop-ins". They are not distributed with the wordpress core and their purpose is to extend functionality, in the db.php case to replace the default database "driver" with another one, for example to communicate with a DB which is not MYSQL.

A typical structure of the files is

class altdb extends wpdb{

    public function __construct(){
        parent::__construct( DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);

    function insert($table, $data, $format = null) {
        // code to override insert

    function query($sql) {
        // code to override query

global $wpdb;
$wpdb = new altdb();

That is a relatively simple example that only overides insert and query but still uses the same DB. You can go much more complex then that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.