Advertisement
Guest User

PHP error

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