Skip to content

wp db query under SQLite: Fatal — Undefined constant "DB_HOST" #3516

Description

@chubes4

Repro

In a Studio site backed by Playground + SQLite drop-in:

wp db query "SELECT option_name FROM wp_options LIMIT 1"

Fatal:

Fatal error: Uncaught Error: Undefined constant "DB_HOST" in
phar:///tmp/wp-cli.phar/vendor/wp-cli/db-command/src/DB_Command.php:1798

Cause

wp db shells out to the mysql binary. The Playground SQLite stack defines no DB_HOST/DB_USER/DB_PASSWORD constants, and mysql isn't available in the runtime anyway. db-command tries to build a mysql --no-defaults … invocation using those constants and crashes before the missing-binary check.

Impact

Any agent or script that falls back to wp db query … for ad-hoc SQL against site state fatals. Affects anyone running Data Machine or Intelligence on Studio/Playground. Workaround (wp eval '$wpdb->get_results(...)') works but isn't obvious, especially to tooling that auto-reaches for wp db.

Suggested fix

Two reasonable options:

  1. In the SQLite integration: short-circuit wp db subcommands with a clean "not available on SQLite — use wp eval or open the SQLite file directly" error. Graceful failure beats a fatal.
  2. Predefine stub DB_* constants early in Playground's WP bootstrap so db-command at least errors with "mysql binary not found" instead of "undefined constant". Less clean but one-line.

Ideally route through (1) — wp db under SQLite should be a no-op with a clear message, not a crash.

Environment

  • Playground dev/combined-fixes + Studio dev/combined-fixes (Studio apps/cli wired to v3.1.20 tarballs from a local self-host)
  • wp-cli 2.12.0 (from the Playground-bundled wp-cli.phar)
  • PHP 8.3, SQLite integration via MDI's db.php drop-in (behavior is the same with stock sqlite-database-integration drop-in per earlier observation)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions