Extend the Database Driver Class (in DB_driver) |
07-17-2017, 01:15 PM
(This post was last modified: 07-17-2017, 01:17 PM by Kaosweaver. Edit Reason: copy-paste error typo fixed )
I need replication to be automatic in the framework (someone does a write function, we need it to automatically select the master table and perform the query with a set comment in union with the PHP plug in we're using to accomplish the correct database to query from)
I've modified the DB_driver.php file in CI 3.1.5, however, I'd like to really do this outside of the core file. Quick notes on what we did: The config database.php file has two lines in it in the $db['default'] array PHP Code: 'replication' => TRUE, The DB_driver.php file has an added function (swipped from CI4's DB files) PHP Code: //-------------------------------------------------------------------- And then I modified the simple_query function like so: PHP Code: public function simple_query($sql) I added a MY_DB_drive.php file in the core folder hoping it would work (pulling out the above changes and making it in to an extended class) like so: PHP Code: <?php But that didn't work. Any pointers on getting what I'd like done without editing the core files?
As far as I know, this has always been too difficult. I've been using CI since 2009, and there's never been an easy way to extend the database classes. You can't just extend the DB_driver class like you expect. The database classes are special, and it's because of the way drivers are applied. Search around the forums and you will eventually find some people doing it, but it's almost as hacky as just hacking system files. I just hack the files, and make really good notes about what I did in a file called CI_UPGRADE_WARNING.txt.
You can overload the core loader to allow you to extend DB drivers the usual way. Code is available here: https://forum.codeigniter.com/thread-685...#pid345512
|
Welcome Guest, Not a member yet? Register Sign In |