In which function/class is the dbprefix added to the table name in Codeigniter Active Record requests?
-
28-10-2019 - |
题
In which function/class is the dbprefix added to the table name in Codeigniter Active Record requests?
I need to dynamically change the prefix based on the table name but cannot find the function which prepends the prefix in the first place.
DB_active_rec.php has a dbprefix() function but this appears to have no effect.
解决方案
It depends on the driver you're using, and it's probably in a few places in that driver too.
Try the DB_active_rec.php file's set_dbprefix()
method to override it. This will get very messy (keeping track of which table you're querying), and I would recommend changing your schema instead.
其他提示
A line taken from the codeigniter site
$this->db->set_dbprefix('newprefix');
In application/config/database.php you can set a prefix variable. Anytime you use Active Records, the prefix is added.