【问题标题】:how to change default database in codeigniter如何在codeigniter中更改默认数据库
【发布时间】:2016-04-27 14:42:58
【问题描述】:

我想更改控制器中的默认数据库,但没有更改。

我正在这样做:

$this->db->close();

$config['default']['database'] = "second";

$this->load->database($config);

【问题讨论】:

    标签: php database codeigniter


    【解决方案1】:

    试试这样的:

    配置:

    $active_group = 'default';
    $db['default']['hostname'] = 'localhost';
    $db['default']['username'] = 'root';
    $db['default']['password'] = '';
    $db['default']['database'] = 'test1';
    
    
    //Another database connection.
    $db['db2']['hostname'] = 'localhost';
    $db['db2']['username'] = 'root';
    $db['db2']['password'] = '';
    $db['db2']['database'] = 'test2';
    

    控制器:

    // close the default connection
    $this->db->close();
    // connect to the other db
    $this->db = $this->load->database('db2', true);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-06
      • 1970-01-01
      • 2017-09-05
      • 1970-01-01
      • 2012-09-27
      • 2023-03-16
      • 2012-10-30
      • 1970-01-01
      相关资源
      最近更新 更多