Advertisement
Guest User

connect.php

a guest
Jul 17th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.69 KB | None | 0 0
  1. <?php
  2.  
  3.     namespace  App\database;
  4.      
  5.     use PDO ;
  6.     use PDOException ;
  7.    
  8.  
  9. class Connection{
  10.     protected $db = "";
  11.     private $username = "root";
  12.     private $password = "";
  13.  
  14.     public function __construct(){
  15.  
  16.  
  17.         try {
  18.                 $this->db = new PDO("mysql:host=localhost;dbname=resume", $this->username, $this->password);
  19.                 // set the PDO error mode to exception
  20.                 $this->db ->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  21.                 $this->db ->setAttribute(PDO::ATTR_EMULATE_PREPARES,false);
  22.  
  23.                 echo "Connected successfully";
  24.  
  25.  
  26.             }
  27.         catch(PDOException $e){
  28.  
  29.                 echo "Connection failed: " . $e->getMessage() . "<br>";
  30.                 die();
  31.             }
  32.     }
  33.  
  34.  
  35.  
  36.  
  37.  
  38. }
  39.  
  40.  ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement