Quantcast
Channel: CodeIgniter Forums - All Forums
Viewing all articles
Browse latest Browse all 14348

Form Validation Check For PDO Connection

$
0
0
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?


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_usernamehtml_entity_decode($database_passwordENT_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 {
            
    
}

I have tried this code but unsure if done it correct.

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;
  }


Viewing all articles
Browse latest Browse all 14348

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>