Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Dbh{
- private $servername;
- private $username;
- private $password;
- private $dbname;
- private $charset;
- protected function connect(){
- $this->servername = "localhost";
- $this->username = "root";
- $this->password = "";
- $this->dbname = "testdb";
- $this->charset = "utf8mb4";
- try{
- $dsn = "mysql:host=".$this->servename.";dbname=".$this->dbname.";charset=".$this->charset;
- $pdo = new PDO($dsn, $this->username, $this->password);
- $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- return $pdo
- } catch (PDOException $e) {
- echo "connection failed: ".$e->getMessage();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement