fix(eloquent): connect to SQLite when WordPress runs on it - #113
Merged
Merged
Conversation
Eloquent always registered a mysql connection built from DB_HOST, DB_NAME, DB_USER and DB_PASSWORD. On WordPress Playground, WordPress Studio and any site with the SQLite Database Integration plugin there is no MySQL, so every Eloquent query failed: on playground.wordpress.net the Database demo's Eloquent ORM page threw on every example (#110). That plugin defines DB_ENGINE ('sqlite') and FQDB (the database file), and keeps WordPress's tables as plain SQLite tables under their MySQL names. Eloquent::connection() now returns a sqlite connection on that file when DB_ENGINE is 'sqlite' and FQDB is defined, and the same mysql connection as before otherwise. Measured on a local WordPress Playground (SQLite Database Integration 3.0.2): the 11 examples of the demo page return their values, and a row written through Eloquent is read back by $wpdb. A table created with Eloquent's schema builder is not visible to WordPress (SHOW TABLES, DESCRIBE) there, because the plugin's MySQL emulation never learns about it: tables still belong to WordPress (migrations, dbDelta).
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
No unresolved blocking issues were identified.
Review effort: Lite
Findings: None
What changed in this PR
Adds SQLite-aware Eloquent connections for WordPress while preserving MySQL behavior.
Changes:
- Selects SQLite using
DB_ENGINEandFQDB. - Preserves MySQL fallback behavior.
- Adds tests for MySQL, SQLite, and fallback configurations.
| File | Description |
|---|---|
tests/Unit/EloquentTest.php |
Tests supported connection configurations. |
src/Database/Eloquent.php |
Implements database-aware connection selection. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This was referenced Sep 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #110.
The problem
Eloquent::init()always registered amysqlconnection built fromDB_HOST,DB_NAME,DB_USERandDB_PASSWORD. WordPress Playground, WordPress Studio and any site running the SQLite Database Integration plugin have no MySQL, so every Eloquent query failed there. On playground.wordpress.net the Database demo's Eloquent ORM page threw on every example.The fix
The SQLite Database Integration plugin defines
DB_ENGINE('sqlite') andFQDB(the database file). It keeps WordPress's tables as plain SQLite tables under their MySQL names, and its text columns areCOLLATE NOCASE, so comparisons stay case-insensitive as on MySQL.Eloquent::connection()returns asqliteconnection onFQDBwhenDB_ENGINEis'sqlite'andFQDBis defined. Otherwise it returns the samemysqlconnection as before, unchanged.Measured on a local WordPress Playground (SQLite Database Integration 3.0.2,
WP_MySQL_On_SQLite):where('user_login', 'ADMIN')findsadmin;$wpdb.One limit, which goes in the docs: a table created with Eloquent's schema builder is readable by
$wpdbwithSELECT, butSHOW TABLESandDESCRIBEdon't list it. The plugin's MySQL emulation never learns about it. Tables still belong to WordPress (WP Bones migrations,dbDelta), and Eloquent works on their data.Tests
tests/Unit/EloquentTest.phphas 4 tests, each in its own process because the constants can be defined only once:DB_ENGINEmysqlstays MySQL;FQDBfile and ignores Playground's sample MySQL credentials;FQDBfalls back to MySQL..claude/scripts/eloquent-live-smoke.shin the workspace:illuminate/database) registers amysqlconnection and counts the same users as$wpdb;src/replaces its framework, and it runs innpx @wp-playground/clifrom a blueprint.$wpdbAccess denied for user 'username_here')[email protected],iPad,Book iMac,Book iPod