CodeIgniter Forums
Temporary DB prefix override - Printable Version

+- CodeIgniter Forums (
+-- Forum: CodeIgniter 4 (
+--- Forum: CodeIgniter 4 Support (
+--- Thread: Temporary DB prefix override (/thread-72954.html)

Temporary DB prefix override - MGatner - 03-05-2019

Is there a way to override the database prefix for a specific query or duration? or a toggle on-off? Scenario is dozens of tables all prefixed and one library-specific table that isn't, so now all my models are built around the non-prefixed name and I want to write a single CLI Command to access the "external" table but don't seem to be able to do it...

RE: Temporary DB prefix override - MGatner - 03-05-2019

Quick update on what I've found so far:
* There is a function "setPrefix()" in CodeIgniter\Database\BaseConnection that allows changing the current database prefix; no luck so far getting a model to implement and reset this, but an option for procedural tasks
* Using the database class to write a query directly allows explicitly naming a table sans prefix: $db->query('SELECT * FROM users');
* Using the query builder class *will* always include the prefix: $builder = $db->table("users") - results in "pre_users"

Hope that helps someone