第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Codeigniter 3 - 即時測試數(shù)據(jù)庫連接 - 不使用 config/database

Codeigniter 3 - 即時測試數(shù)據(jù)庫連接 - 不使用 config/database

PHP
茅侃侃 2022-07-22 18:50:05
我正在為我的應(yīng)用程序創(chuàng)建一個 Web 安裝程序。在安裝程序中,我將允許用戶輸入服務(wù)器、用戶名、密碼和數(shù)據(jù)庫名稱的值?,F(xiàn)在使用這個值,我將如何驗(yàn)證我的應(yīng)用程序是否可以與數(shù)據(jù)庫建立連接注意:我沒有使用該config/database.php文件。相反,我將使用用戶發(fā)布的數(shù)據(jù)并測試連接。如果成功,會將這些值寫入config/database.php我的控制器代碼如下:$host = $this->input->post('dbserver');$username = $this->input->post('dbusername');$password = $this->input->post('dbpassword');$name = $this->input->post('dbname');if(<can connect with the database using the above>) // <---- This is what I'm looking for{   // write to the config/database.php file}
查看完整描述

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í)例(方法鏈接)


查看完整回答
反對 回復(fù) 2022-07-22
?
暮色呼如

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

}


查看完整回答
反對 回復(fù) 2022-07-22
  • 2 回答
  • 0 關(guān)注
  • 126 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號