2013-04-23 70 views
0

我有一個表單,其中使用CodeIgniter來連接到數據庫。數據由表單中的用戶填寫。 是否有可能知道連接是否已建立?嘗試手動連接

$drive  = $this->input->post('drive'); 
$hostname = $this->input->post('hostname'); 
$database = $this->input->post('database'); 
$username = $this->input->post('username'); 
$password = $this->input->post('password'); 
$base  = $this->input->post('base'); 

$db = array(
       'hostname' => $hostname, 
       'username' => $username, 
       'password' => $password, 
       'database' => $database, 
       'dbdriver' => $drive, 
       'db_debug' => FALSE); 

     $cn = $this->load->database($db); 

if ($cn) { echo 'ok'; } else {echo 'nops';} 
+0

如果CI沒有報告一個數據庫錯誤,那麼在建立連接 - 嘗試運行一個簡單的查詢,以測試它 – Shomz 2013-04-23 19:46:13

+0

是不可能的,因爲我輸入了錯誤的數據進行登錄,$ this-> db的print_r顯示的數據是錯誤的。 – Tommy 2013-04-23 20:00:39

+0

做一個表演表 – Drewdin 2013-04-23 20:01:54

回答

2

你被明確禁止的錯誤消息與'db_debug' => false,所以我不認爲你會得到CI投訴。但是你可以爲連接測試做the same as the Database library does(因爲每個場是公開的):

// your original code here 
$conn_success = $cn->conn_id ? true : false;