Codeigniter change database config at runtime

前端 未结 5 1622
没有蜡笔的小新
没有蜡笔的小新 2021-01-03 00:44

Can I change the database config per method in a controller?

$db[\'default\'][\'db_debug\'] = TRUE;

The default is TRUE, while

5条回答
  •  既然无缘
    2021-01-03 01:18

    you must add function on system/database/DB_driver.php

    function debug_on()
    {
         $this->db_debug = TRUE;
         return TRUE;
    }
    
    function debug_off()
    {
         $this->db_debug = FALSE;
         return FALSE;
    }
    

    after that you can simply do this command to changes at run-time

    $this->db->debug_off();
    $this->db->reconnect();
    

提交回复
热议问题