Welcome Guest, Not a member yet? Register   Sign In
DB test connection details
#1

[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.


Messages In This Thread
DB test connection details - by El Forum - 05-01-2011, 05:57 AM
DB test connection details - by El Forum - 05-01-2011, 06:11 AM
DB test connection details - by El Forum - 05-02-2011, 12:03 AM
DB test connection details - by El Forum - 05-04-2011, 05:24 AM
DB test connection details - by El Forum - 05-04-2011, 02:01 PM
DB test connection details - by El Forum - 05-04-2011, 08:56 PM



Theme © iAndrew 2016 - Forum software by © MyBB