2 回答
TA貢獻(xiàn)1784條經(jīng)驗(yàn) 獲得超9個贊
根據(jù)codeigniter 文檔,您可以使用手動連接到數(shù)據(jù)庫執(zhí)行以下操作:
$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 設(shè)置為 TRUE,則加載 CI_DB 實(shí)例或 FALSE 失敗,否則 CI_Loader 實(shí)例(方法鏈接)
TA貢獻(xiàn)1853條經(jīng)驗(yàn) 獲得超9個贊
好的。我想到了。
使用TRUEorFALSE作為第二個參數(shù)$this->load->database()總是返回一個對象,因此檢查是徒勞的,因?yàn)榧词故褂缅e誤的憑據(jù)if($this->load->database()),它也總是會評估。TRUE
所以我繼續(xù)這樣做:
@$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 關(guān)注
- 126 瀏覽
添加回答
舉報
