How to connect with user specified database in codeigniter

前端 未结 3 1106
慢半拍i
慢半拍i 2020-12-06 21:54

I have a project in which i have to connect with user specified database. I want to implement it in a proper codeigniter\'s style but i dont know how can i do that codeignit

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-06 22:47

    According to the guide, you can manually pass database connectivity settings via the third parameter of $this->load->model:

    $config['hostname'] = "localhost";
    $config['username'] = "myusername";
    $config['password'] = "mypassword";
    $config['database'] = "mydatabase";
    $config['dbdriver'] = "mysql";
    $config['dbprefix'] = "";
    $config['pconnect'] = FALSE;
    $config['db_debug'] = TRUE;
    
    $this->load->model('Model_name', '', $config);
    // or as gorelative notes, to access multiple databases:
    $DB2 = $this->load->database($config, TRUE);
    

提交回复
热议问题