2 回答
TA贡献1784条经验 获得超9个赞
根据codeigniter 文档,您可以使用手动连接到数据库执行以下操作:
$config['hostname'] = $this->input->post('dbserver');
$config['username'] = $this->input->post('dbusername');
$config['password'] = $this->input->post('dbpassword');
$config['database'] = $this->input->post('dbname');
$config['dbdriver'] = {driver_to_use};
$config['dbprefix'] = {prefix};
$config['pconnect'] = {bool};
$config['db_debug'] = {bool};
$config['cache_on'] = {bool};
$config['cachedir'] = {cachedir};
$config['char_set'] = {char_set};
$config['dbcollat'] = {dbcollat};
if($this->load->database($config, TRUE))
{
// Write the db config file
}
在加载器类参考之后:
返回:如果 $return 设置为 TRUE,则加载 CI_DB 实例或 FALSE 失败,否则 CI_Loader 实例(方法链接)
TA贡献1853条经验 获得超9个赞
好的。我想到了。
使用TRUEorFALSE作为第二个参数$this->load->database()总是返回一个对象,因此检查是徒劳的,因为即使使用错误的凭据if($this->load->database()),它也总是会评估。TRUE
所以我继续这样做:
@$this->load->database($config, FALSE, TRUE); // using @ to avoid warnings in case of wrong credentials
if(@$this->db->initialize()) // again use @ to avoid error messages
{
// now this verifies it truly connected
}
- 2 回答
- 0 关注
- 96 浏览
添加回答
举报