Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
5c54007
Initial plan
Copilot Apr 2, 2026
cfe43e7
Add wpdb fallback for wp db query when mysql/mariadb binary is unavai…
Copilot Apr 2, 2026
ea5dea1
Improve wpdb fallback: add escapeshellarg and table prefix support
Copilot Apr 2, 2026
5375be8
Add load.php, extend wpdb fallback to run_query() and import command
Copilot Apr 3, 2026
47906b9
Apply suggestion from @swissspidy
swissspidy Apr 3, 2026
2d3706f
Add Behat tests for wpdb fallback in drop, reset, and import commands
Copilot Apr 3, 2026
9ea27c2
Apply suggestions from code review
swissspidy Apr 3, 2026
f85364e
Merge branch 'main' into copilot/fix-wp-db-query-fallback
swissspidy Apr 21, 2026
adc0d52
Fix split_sql_statements() to handle backslash-escaped quotes inside …
Copilot May 27, 2026
41b410d
Fix: change I run to I try in db-import fallback test to allow STDERR…
Copilot May 28, 2026
ae8b0b6
Merge branch 'main' into copilot/fix-wp-db-query-fallback
swissspidy Jul 13, 2026
72c5468
Fix issue after merge
swissspidy Jul 13, 2026
62d9d98
Fix run_query() WP 4.9 compatibility: use mysqli instead of wpdb
Copilot Jul 14, 2026
7e177ee
Address code review: fix edge cases in run_query_via_mysqli()
Copilot Jul 14, 2026
60262b5
Restore wpdb fallback in run_query() and fix WP 4.9 compatibility
Copilot Jul 14, 2026
23355d6
Fix WP 4.9: use run_query_via_mysqli() for drop/reset, keep wpdb for …
Copilot Jul 14, 2026
6414ec5
Replace maybe_load_wpdb() with direct mysqli in wpdb_query() and wpdb…
Copilot Jul 14, 2026
e1d6e78
Fix code review: remove redundant cast, handle NULL as 'NULL' in quer…
Copilot Jul 14, 2026
b6489cb
Fix split_sql_statements() to execute MySQL conditional comments (/*!…
Copilot Jul 14, 2026
ec70aa9
Improve split_sql_statements: rename $peek, clarify version-digit loo…
Copilot Jul 14, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions features/db-import.feature
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,34 @@ Feature: Import a WordPress database
Success: Imported from 'wp_cli_test.sql'.
"""

@require-mysql-or-mariadb
Scenario: Database import falls back to wpdb when mysql binary is unavailable
Given a WP install
And a fake-bin/mysql file:
"""
#!/bin/sh
exit 127
"""
And a fake-bin/mariadb file:
"""
#!/bin/sh
exit 127
"""

When I run `wp db export wp_cli_test.sql`
Then the wp_cli_test.sql file should exist

When I run `chmod +x fake-bin/mysql fake-bin/mariadb`
And I try `env PATH={RUN_DIR}/fake-bin:$PATH wp db import wp_cli_test.sql --debug`
Then STDOUT should be:
"""
Success: Imported from 'wp_cli_test.sql'.
"""
And STDERR should contain:
"""
MySQL/MariaDB binary not available, falling back to wpdb for import.
"""

# SQLite doesn't support the --dbuser flag.
@require-mysql-or-mariadb
Scenario: Import from database name path by default with passed-in dbuser/dbpass
Expand Down
26 changes: 26 additions & 0 deletions features/db-query.feature
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,29 @@ Feature: Query the database with WordPress' MySQL config
"""
ANSI
"""

@require-mysql-or-mariadb
Scenario: Database querying falls back to wpdb when mysql binary is unavailable
Given a WP install
And a fake-bin/mysql file:
"""
#!/bin/sh
exit 127
"""
And a fake-bin/mariadb file:
"""
#!/bin/sh
exit 127
"""

When I run `chmod +x fake-bin/mysql fake-bin/mariadb`
And I try `env PATH={RUN_DIR}/fake-bin:$PATH wp db query "SELECT COUNT(ID) FROM wp_users;" --debug`
Then STDOUT should be:
"""
COUNT(ID)
1
"""
And STDERR should contain:
"""
MySQL/MariaDB binary not available, falling back to wpdb.
"""
52 changes: 51 additions & 1 deletion features/db.feature
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,58 @@ Feature: Perform database operations
Query succeeded. Rows affected: 1
"""

@require-sqlite @skip-windows
@require-mysql-or-mariadb
Scenario: Database drop falls back to wpdb when mysql binary is unavailable
Given a WP install
And a fake-bin/mysql file:
"""
#!/bin/sh
exit 127
"""
And a fake-bin/mariadb file:
"""
#!/bin/sh
exit 127
"""

When I run `chmod +x fake-bin/mysql fake-bin/mariadb`
And I try `env PATH={RUN_DIR}/fake-bin:$PATH wp db drop --yes --debug`
Then STDOUT should contain:
"""
Success: Database dropped.
"""
And STDERR should contain:
"""
Query via mysqli:
"""

@require-mysql-or-mariadb
Scenario: Database reset falls back to wpdb when mysql binary is unavailable
Given a WP install
And a fake-bin/mysql file:
"""
#!/bin/sh
exit 127
"""
And a fake-bin/mariadb file:
"""
#!/bin/sh
exit 127
"""

When I run `chmod +x fake-bin/mysql fake-bin/mariadb`
And I try `env PATH={RUN_DIR}/fake-bin:$PATH wp db reset --yes --debug`
Then STDOUT should contain:
"""
Success: Database reset.
"""
And STDERR should contain:
"""
Query via mysqli:
"""

# Skipped on Windows due to persistent file locking issues when run via Behat.
@require-sqlite @skip-windows
Scenario: SQLite DB CRUD operations
Given a WP install
And a session_yes file:
Expand Down
Loading
Loading