php - Try Manual Connection
845
I have a form with fields to make a connection to the database using CodeIgniter. The data is filled in by the users in the form. Is it possible to know if the connection is established or not?
$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';}
Answer
Solution:
You are explicitly disabling error messages with the
'db_debug' => false
, so I don't think you will get CI complaints. However you can do the same as the Database library does for connection testing (since every field is public):