Guest User

dbc.inc.php

a guest
Sep 22nd, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.72 KB | None | 0 0
  1. <?php
  2.      class Dbh{
  3.         private $servername;
  4.         private $username;
  5.         private $password;
  6.         private $dbname;
  7.         private $charset;
  8.  
  9.  
  10.         protected function connect()
  11.         {
  12.             $this->servername="localhost";
  13.             $this->username="root";
  14.             $this->password="";
  15.             $this->dbname="mysqlioop";
  16.             $this->charset="utf8mb4";
  17.  
  18.             try {
  19.                     $dsn ="mysql:host=".$this->servername.";dbname =".$this->dbname.";charset =" .$this->charset;
  20.  
  21.                     $pdo = new PDO($dsn,$this->username,$this->password);
  22.                     $pdo->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
  23.  
  24.                     return $pdo;
  25.                        
  26.             } catch (PDOException $e) {
  27.                 echo "Connection failed".$e->getMessage();
  28.                
  29.             }
  30.  
  31.  
  32.            
  33.         }
  34.  
  35.      }
  36.  
  37.  ?>
Add Comment
Please, Sign In to add comment