WP Debug Toolkit 1.1.0 is LIVE. Get $300 discount on the lifetime deal now
Use Discount Code WPDTLTD

The db.php drop-in is a WordPress database override file that WP Debug Toolkit (WPDT) installs at wp-content/db.php. It extends the default wpdb class to capture full PHP backtraces before each query, which enables component attribution, caller identification, and detailed performance analysis in the Query Viewer.

What it does

WordPress supports a “drop-in” file at wp-content/db.php. When this file exists, WordPress loads it early in its bootstrap process and uses it instead of the default database class.

WPDT’s drop-in defines a DBTK_DB class that extends wpdb. The custom class overrides the query() method to do two things before each query executes:

  1. Capture a backtrace — calls debug_backtrace() to record the full chain of PHP function calls leading to the query.
  2. Record the result — stores the number of affected rows or any WP_Error returned by the query.

This data is attached to each query entry and later written to the encrypted query log during the PHP shutdown phase.

Enhanced vs basic logging

Without the drop-in, WPDT falls back to basic logging using the WordPress SAVEQUERIES constant. Here is what each mode provides:

CapabilityBasic (SAVEQUERIES)Enhanced (db.php)
SQL statementYesYes
Execution timeYesYes
BacktraceBasic — parsed from SAVEQUERIES comma-separated stack traceYes — full PHP call stack with file, line, and function for each frame
Component attributionBasic — derived from parsed backtraceYes — identifies the plugin, theme, or core subsystem responsible
Caller functionBasic — derived from parsed backtraceYes — the specific function or method that triggered the query
Affected rows / errorsNoYes

Enhanced logging provides full, structured backtraces with precise component attribution and caller identification. Basic mode parses backtrace data from the SAVEQUERIES comma-separated stack trace, which provides partial component and caller information but with less detail and accuracy.

Installation

The drop-in installs automatically when you enable enhanced query logging. Two ways to enable it:

From the admin dashboard:

  1. Go to Debug Toolkit > Overview.
  2. In the Database Monitor card, toggle enhanced query logging on.

From WP-CLI:

wp dbtk query-log enable

WPDT copies its db.php template to wp-content/db.php. No manual file handling is needed.

Removal

The drop-in is removed automatically when you disable enhanced query logging:

From the admin dashboard:

  1. Go to Debug Toolkit > Overview.
  2. Toggle enhanced query logging off.

From WP-CLI:

wp dbtk query-log disable

WPDT deletes wp-content/db.php. Query logging continues in basic mode (SAVEQUERIES) if query logging itself is still enabled.

Conflicts

WordPress loads only one db.php file. If another plugin has already placed a db.php in wp-content/, WPDT cannot install its own.

Plugins that use db.php

Several plugins install their own db.php drop-in:

  • Query Monitor (by John Blackbourn) — installs a db.php for its own backtrace capture
  • Debug Bar — older debugging plugin with a similar drop-in
  • Some caching plugins — certain object cache or database caching plugins use db.php to intercept queries

Only one db.php can be active at a time. If a conflict exists, WPDT falls back to basic logging automatically. You still get SQL and timing data, but without backtraces or component attribution.

Checking which db.php is active

Look at the contents of wp-content/db.php. If it contains a reference to the DBTK_DB class, it is WPDT’s drop-in:

grep "DBTK_DB" wp-content/db.php

If the file exists but does not reference DBTK_DB, another plugin owns it.

Resolving conflicts

If you want WPDT’s enhanced logging and another plugin’s db.php is in the way:

  1. Identify which plugin installed the existing db.php (check its contents for class names or plugin references).
  2. Disable that plugin’s drop-in through its own settings, if possible.
  3. Enable WPDT’s enhanced query logging. WPDT installs its own db.php.

You do not need both — WPDT provides its own backtrace capture and does not depend on another plugin’s db.php.

Troubleshooting

Enhanced logging enabled but no backtraces

Another plugin’s db.php may be overriding WPDT’s drop-in. Check wp-content/db.php to confirm it references the DBTK_DB class. If it does not, another plugin replaced the file after WPDT installed it. Disable the conflicting plugin’s drop-in and re-enable WPDT’s enhanced logging.

Permission errors when enabling

The PHP process needs write access to the wp-content/ directory to create or remove db.php. If you see a permission error:

  • Check that the directory permissions on wp-content/ allow writing (typically 0755 with the web server user as owner).
  • On managed hosting, the web server user may differ from the file owner. Contact your host if you cannot resolve this.

Drop-in not removed after disabling

If wp-content/db.php remains after you disable enhanced logging, the file may have been modified by another plugin or the PHP process may lack delete permission. You can remove it manually:

rm wp-content/db.php

This is safe — WordPress runs without db.php and uses its default wpdb class.

On this page
Try WP Debug Toolkit
The best error log viewer with amazing developer tools to help you troubleshoot your WordPress site securely and efficiently. Something something more.