Skip to content

PHP Fatal on web requests with root-owned SQLite file (3.1.3) — [RESOLVED: testing artifact, UX suggestion inside] #610

Open

Description

@x-rush

[RESOLVED — NOT A BUG] The reported fatal was caused by my own test harness (the SQLite
database file was created by a root-privileged wp-cli run and was unreadable by the web server
user). After fixing file ownership, 3.1.3 works flawlessly on WP 7.1.4 / PHP 8.3 & 8.4, including
a fully migrated 339-post site. Root-cause analysis and a UX improvement suggestion are in
this comment.
Safe to close as not-a-bug.

Description

On a clean WordPress 7.1.4 install with the SQLite plugin 3.1.3 active, every web request logs a PHP Fatal error:

PHP Fatal error:  Uncaught RuntimeException: Cannot escape data without an active database connection. in /var/www/html/wp-content/plugins/sqlite-database-integration/wp-includes/sqlite/class-wp-sqlite-db.php:324

thrown from class-wp-sqlite-db.php:324 (WP_SQLite_DB::_real_escape(), if ( ! $this->dbh )).

Pages still render with HTTP 200, so the site appears to work — but the fatal is logged on every request (1–3× per request, including wp-cron.php), meaning dbh is not initialized at wp-settings.php:180 (wp_not_installed() → is_blog_installed() → wp_load_alloptions() → esc_sql()).

WP-CLI requests on the same site/database/drop-in never trigger it — the error is specific to the web SAPI context.

Environment

  • WordPress 7.1.4 (fresh install)
  • PHP 8.4.27 (wordpress:php8.4-apache image), pdo_sqlite loaded
  • Plugin 3.1.3 (from wordpress.org stable)
  • MySQL 8.4.11 present as the original database (plugin drop-in switches to SQLite)
  • Docker (Linux containers), Apache web SAPI

Reproduction (controlled A/B)

Setup A — pristine install. Fresh wordpress:php8.4-apache + MySQL 8.4, image-generated wp-config.php, core installed via wp-cli. Plugin installed from wordpress.org, activated via wp-cli, drop-in written exactly as sqlite_plugin_copy_db_file() does (the db.copy template with placeholders substituted). Fresh empty SQLite database, zero custom content.

Setup B — migrated install. Separate WordPress instance with production-derived wp-config.php, 15-table site (203 posts + custom post type + comments), data converted from a mysqldump and loaded into the SQLite file, W3TC deactivated.

Result: identical fatals in both setups. In Setup A: 9 fatals for 9 web requests (home, ?p=1, wp-cron.php). WP_DEBUG_LOG on, SQLITE_BUSY_TIMEOUT=10000 + SQLITE_JOURNAL_MODE=WAL made no difference. WP-CLI commands (wp post list, wp option get) on the same sites run clean.

Minimal reproduction

  1. WordPress 7.1.4 on PHP 8.4 with MySQL, plugin 3.1.3 activated
  2. Enable the SQLite drop-in (admin confirm flow or the db.copy equivalent)
  3. wp core install into SQLite (fresh)
  4. curl the site home → HTTP 200, but debug.log contains the fatal above
  5. wp post list via CLI on the same site → no error

Expected behavior

No fatal should be logged on a healthy request; _real_escape() should not be reached with an uninitialized dbh during is_blog_installed().

Notes

  • The fatal occurs before plugins load (wp-settings.php:180), so it is not plugin-interference from the site side.
  • The same drop-in and database work correctly under WP-CLI, which suggests the connection lifecycle (dbh initialization) differs between web and CLI contexts.
  • Happy to provide additional dumps/traces if helpful.

Activity

  1. x-rush commented on Nov 5, 2026

    @x-rush
    Author

    Correction + additional data points (site is fully broken on the web path)

    After posting the report I instrumented a single request (curl -v) and found the HTTP 200 responses are misleading: the response body is not a rendered page at all — it is a ~1 KB fragment that ends mid-text with the fatal message:

    ...ation/wp-includes/sqlite/class-wp-sqlite-db.php on line 324
    

    So on the web path the site is fully broken (no page ever renders; every request returns a 200-codenamed error fragment). The "pages still render with HTTP 200" wording in the original report should be read as "error fragment returned with a 200 status".

    Additional data points:

    1. PHP 8.3 reproduces it too — identical setup on wordpress:php8.3-apache (PHP 8.3.36): same fatal on every request. Not specific to the PHP 8.4 PDO-compat trait.
    2. DISABLE_WP_CRON = true — fatals persist on plain page requests, so the wp-cron spawn loopback is not the trigger.
    3. SQLITE_BUSY_TIMEOUT=10000 + SQLITE_JOURNAL_MODE=WAL — no effect (reported earlier).
    4. WP-CLI on the same SQLite database remains fully functional (wp core install, wp post list, wp option get all clean), which is why wp core install succeeds and only web requests break.

    Happy to test any proposed fix against these two sandboxes (PHP 8.3 / 8.4).

  2. x-rush commented on Nov 5, 2026

    @x-rush
    Author

    Full evidence: complete debug.log entries + raw HTTP transcript + version manifest

    Version manifest

    WordPress:            7.1.4 (fresh, zero custom content)
    PHP:                  8.3.36 (wordpress:php8.3-apache image) — also reproduces on 8.4.27
    Plugin:               sqlite-database-integration 3.1.3 (wordpress.org stable)
    MySQL:                8.4.11 (original database; drop-in switches to SQLite)
    Drop-in:              wp-content/db.php per db.copy template (SQLITE_DB_DROPIN_VERSION 1.8.0)
    DB_PATH:              /var/www/html/wp-content/database/p83.sqlite
    wp-config constants:  WP_DEBUG / WP_DEBUG_LOG true, DISABLE_WP_CRON true, SQLITE_BUSY_TIMEOUT 10000, SQLITE_JOURNAL_MODE WAL
    

    Complete debug.log (single home-page request, unmodified)

     Container wp-pristine83-db-1 Running 
     Container wp-pristine83-cli-run-4b167478115b Creating 
     Container wp-pristine83-cli-run-4b167478115b Created 
    [05-Nov-2026 00:48:35 UTC] PHP Fatal error:  Uncaught RuntimeException: Cannot escape data without an active database connection. in /var/www/html/wp-content/plugins/sqlite-database-integration/wp-includes/sqlite/class-wp-sqlite-db.php:324
    Stack trace:
    #0 /var/www/html/wp-includes/class-wpdb.php(1307): WP_SQLite_DB->_real_escape('yes')
    #1 /var/www/html/wp-includes/formatting.php(4529): wpdb->_escape(Array)
    #2 /var/www/html/wp-includes/option.php(627): esc_sql(Array)
    #3 /var/www/html/wp-includes/functions.php(1794): wp_load_alloptions()
    #4 /var/www/html/wp-includes/load.php(943): is_blog_installed()
    #5 /var/www/html/wp-settings.php(180): wp_not_installed()
    #6 /var/www/html/wp-config.php(142): require_once('/var/www/html/w...')
    #7 /var/www/html/wp-load.php(50): require_once('/var/www/html/w...')
    #8 /var/www/html/wp-blog-header.php(13): require_once('/var/www/html/w...')
    #9 /var/www/html/index.php(17): require('/var/www/html/w...')
    #10 {main}
      thrown in /var/www/html/wp-content/plugins/sqlite-database-integration/wp-includes/sqlite/class-wp-sqlite-db.php on line 324
    [05-Nov-2026 00:48:35 UTC] PHP Fatal error:  Uncaught RuntimeException: Cannot escape data without an active database connection. in /var/www/html/wp-content/plugins/sqlite-database-integration/wp-includes/sqlite/class-wp-sqlite-db.php:324
    Stack trace:
    #0 /var/www/html/wp-includes/class-wpdb.php(1307): WP_SQLite_DB->_real_escape('yes')
    #1 /var/www/html/wp-includes/formatting.php(4529): wpdb->_escape(Array)
    #2 /var/www/html/wp-includes/option.php(627): esc_sql(Array)
    #3 /var/www/html/wp-includes/functions.php(1794): wp_load_alloptions()
    #4 /var/www/html/wp-includes/load.php(943): is_blog_installed()
    #5 /var/www/html/wp-settings.php(180): wp_not_installed()
    #6 /var/www/html/wp-config.php(142): require_once('/var/www/html/w...')
    #7 /var/www/html/wp-load.php(50): require_once('/var/www/html/w...')
    #8 /var/www/html/wp-cron.php(46): require_once('/var/www/html/w...')
    #9 {main}
      thrown in /var/www/html/wp-content/plugins/sqlite-database-integration/wp-includes/sqlite/class-wp-sqlite-db.php on line 324
    
    

    Raw HTTP transcript (same request family; curl -v http://127.0.0.1:8092/)

    > GET / HTTP/1.1
    > Host: 127.0.0.1:8092
    > User-Agent: curl/8.23.0
    > Accept: */*
    > 
    < HTTP/1.1 200 OK
    < Date: Thu, 05 Nov 2026 00:48:34 GMT
    < Server: Apache/2.4.69 (Debian)
    < X-Powered-By: PHP/8.3.36
    < Vary: Accept-Encoding
    < Content-Length: 1050
    < Content-Type: text/html; charset=UTF-8
    < 
    

    Full response body (1050 bytes — this is the entire page, no HTML wrapper, no rendered content)

    
    Fatal error: Uncaught RuntimeException: Cannot escape data without an active database connection. in /var/www/html/wp-content/plugins/sqlite-database-integration/wp-includes/sqlite/class-wp-sqlite-db.php:324
    Stack trace:
    #0 /var/www/html/wp-includes/class-wpdb.php(1307): WP_SQLite_DB->_real_escape('yes')
    #1 /var/www/html/wp-includes/formatting.php(4529): wpdb->_escape(Array)
    #2 /var/www/html/wp-includes/option.php(627): esc_sql(Array)
    #3 /var/www/html/wp-includes/functions.php(1794): wp_load_alloptions()
    #4 /var/www/html/wp-includes/load.php(943): is_blog_installed()
    #5 /var/www/html/wp-settings.php(180): wp_not_installed()
    #6 /var/www/html/wp-config.php(142): require_once('/var/www/html/w...')
    #7 /var/www/html/wp-load.php(50): require_once('/var/www/html/w...')
    #8 /var/www/html/wp-blog-header.php(13): require_once('/var/www/html/w...')
    #9 /var/www/html/index.php(17): require('/var/www/html/w...')
    #10 {main}
      thrown in /var/www/html/wp-content/plugins/sqlite-database-integration/wp-includes/sqlite/class-wp-sqlite-db.php on line 324
    
    

    Note the visitor-facing symptom: the page is literally the raw PHP fatal dump (appears blank/black in a browser with a dark color scheme). WP-CLI on the same database and drop-in (wp core install, wp post list, wp option get) runs with zero errors.

    Both sandboxes (PHP 8.3 / 8.4) are kept alive and I can test any proposed fix immediately.

  3. x-rush commented on Nov 5, 2026

    @x-rush
    Author

    Resolution: not a plugin bug — root cause found (my test harness's file ownership)

    Please accept my apologies for the noise — with full root-cause analysis this turns out to be a test-harness artifact, not a plugin defect.

    Root cause

    My sandbox flow ran wp-cli as root (default wordpress:cli user override), so core install created the SQLite database file owned by root:root with mode 600. The web server runs as www-data, which could neither read nor open that file. The storage layer failed silently at boot, dbh was never initialized, and the first esc_sql() call surfaced the generic Cannot escape data without an active database connection fatal — far away from the actual cause.

    After chown -R www-data:www-data on the database directory (and nothing else):

    • Every previously-failing request returns a fully rendered page
    • Zero fatals in debug.log across home/article/page/wp-cron requests
    • Same result on PHP 8.3.36 and 8.4.27
    • Write path verified: wp post create + home page listing via SQLite
    • A full migrated site (15 tables, 339 posts + custom post type, options, comments converted from a mysqldump) renders correctly with zero errors

    Both "pristine" and "migrated" sandboxes are now fully working on 3.1.3 + WP 7.1.4.

    Why it fooled me (and possibly worth addressing)

    WP-CLI worked flawlessly throughout (root could always access the file), so the site looked healthy from the admin/CLI side while every web request failed. The fatal message names the symptom (escaping before an active connection) rather than the cause (storage open/permission failure), which cost significant debugging time.

    Suggestion (non-blocking, UX improvement)

    If WP_SQLite_Storage::initialize() fails to open/create the database file (e.g. EACCES), throwing an explicit, actionable error at that point — e.g. "Cannot open SQLite database at : permission denied (current uid )" — would turn this debugging session from hours into minutes.

    This issue can be closed as not-a-bug. Thank you for the well-built plugin — 3.1.3 has been rock solid once the file permissions are correct, including a fully migrated 339-post site.

  4. changed the title [-]PHP Fatal on every web request: Cannot escape data without an active database connection (3.1.3, WP 7.1.4, PHP 8.4)[/-] [+]PHP Fatal on web requests with root-owned SQLite file (3.1.3) — [RESOLVED: testing artifact, UX suggestion inside][/+] on Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions