I have this function below for my call back.
I have set the check for MySQL to see if can connect. But I am not sure how to do it for check connect like I have done for mysqli but for PDO
Can some one give me a example or idea?
I have tried this code but unsure if done it correct.
I have set the check for MySQL to see if can connect. But I am not sure how to do it for check connect like I have done for mysqli but for PDO
Can some one give me a example or idea?
PHP Code:
public function check_db_connect() {
$database_hostname = $this->input->post('database_hostname');
$database_username = $this->input->post('database_username');
$database_password = $this->input->post('database_password');
$database_name = $this->input->post('database_name');
$database_driver = $this->input->post('database_driver');
$database_prefix = $this->input->post('database_prefix');
if ($database_driver == 'mysqli') {
$mysql = @new MySQLi($database_hostname, $database_username, html_entity_decode($database_password, ENT_QUOTES, 'UTF-8'), $database_name);
if ($mysql->connect_error) {
$this->form_validation->set_message('check_db_connect', $mysql->connect_error);
return false;
} else {
return true;
$mysql->close();
}
}
if ($database_driver == 'pdo') {
} else {
}
}
PHP Code:
if ($database_driver == 'pdo') {
try {
$DBH = new PDO("mysql:host=$database_hostname;dbname=$database_name", $database_username, $database_password);
$DBH = null;
return true;
}
catch(PDOException $e) {
$this->form_validation->set_message('check_db_connect', $e->getMessage());
return false;
}
}