Welcome Guest, Not a member yet? Register   Sign In
Temporary DB prefix override
#1

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...
Reply
#2

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
Reply




Theme © iAndrew 2016 - Forum software by © MyBB