Skip to content

Add wpdb fallback for wp db query when mysql/mariadb binary is unavailable#320

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/fix-wp-db-query-fallback
Draft

Add wpdb fallback for wp db query when mysql/mariadb binary is unavailable#320
Copilot wants to merge 3 commits intomainfrom
copilot/fix-wp-db-query-fallback

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 2, 2026

wp db query currently requires the mysql/mariadb CLI binary, causing failures with drop-in database engines (HyperDB, custom drivers) or environments where the binary simply isn't installed.

Changes

src/DB_Command.php

  • is_mysql_binary_available() — probes for the mysql/mariadb binary via /usr/bin/env <binary> --version; result is statically cached
  • maybe_load_wpdb() — loads the minimal WordPress files needed for $wpdb (compat.php, plugin.php, functions.php, class-wpdb.php), includes any wp-content/db.php drop-in (HyperDB et al.), and falls back to creating a plain wpdb instance with wp-config.php credentials + $table_prefix
  • wpdb_query() — executes arbitrary SQL via $wpdb; mirrors the mysql-path behaviour (row-count reporting for DML, formatted tabular output for SELECT, --skip-column-names support)
  • query() — after the existing SQLite branch, checks binary availability and routes to the new wpdb path when absent:
if ( ! $this->is_mysql_binary_available() ) {
    WP_CLI::debug( 'MySQL/MariaDB binary not available, falling back to wpdb.', 'db' );
    $this->maybe_load_wpdb();
    $this->wpdb_query( $query, $assoc_args );
    return;
}

features/db-query.feature

Added a @require-mysql-or-mariadb scenario that shadows the real binary with a fake exit 127 script via PATH prepending, then asserts the query succeeds and the debug message confirms the fallback was taken.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • example.com
    • Triggering command: /usr/bin/php /usr/bin/php /home/REDACTED/work/db-command/db-command/vendor/wp-cli/wp-cli/bin/../php/boot-fs.php core install --url=REDACTED --title=WP CLI Site --admin_user=admin --admin_email=admin@example.com --admin_password=password1 --skip-email hp kFunctions.php .php�� ain..copilot/fix-wp-db-query-fallback ss.php k/_temp/copilot-developer-action-main/dist/gh-gpgsign/gh-gpgsign-linux-x86_64 mmand.php Autoloader.php de/node/bin/git k/_temp/copilot-developer-actionanalyse (dns block)
    • Triggering command: /usr/bin/php /usr/bin/php /home/REDACTED/work/db-command/db-command/vendor/wp-cli/wp-cli/bin/../php/boot-fs.php core install --url=REDACTED --title=WP CLI Site --admin_user=admin --admin_email=admin@example.com --admin_password=password1 --skip-email ools/sh git rev-�� ain..copilot/fixOUTPUT cut command/vendor/b168.63.129.16 ain..copilot/fixphp (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copilot AI changed the title [WIP] Fix wp db query to fallback using WPDB Add wpdb fallback for wp db query when mysql/mariadb binary is unavailable Apr 2, 2026
Copilot AI requested a review from swissspidy April 2, 2026 21:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

query shouldn't require mysql/mariadb cli tools

2 participants