[eluser]Brad Martin[/eluser]
Building an installation function and i need to validate the database connection details that the user inputs.
I can't seem to find away to do this using codeigniters's database class.
have attempted the following but no success.
Code:
$config['hostname'] = $this->input->post('database_host');
$config['username'] = $this->input->post('username');
$config['password'] = $this->input->post('password');
$config['database'] = $this->input->post('database_name');
$config['dbdriver'] = "mysql";
$config['dbprefix'] = "";
$config['pconnect'] = FALSE;
$config['db_debug'] = FALSE;
$config['cache_on'] = FALSE;
$config['cachedir'] = "";
$config['char_set'] = "utf8";
$config['dbcollat'] = "utf8_general_ci";
if($this->load->database($config)){
// details are correct
}else{
// details are incorrect
}
After the connection details have been validated i use preg_replace(); to modify ./application/config/database.php to include the details.
I can get the result i want by using mysql_connect() however i would like to use codeigniter for this if possible.
I would think that when you call $this->load->database($config); that if for any reason it won't connect that codeigniter would return FALSE however that doesn't seem to be the case.