Advertisement
oimtrust

database_crud-pdo-oop

Dec 28th, 2016
2,165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.58 KB | None | 0 0
  1. <?php
  2.     /**
  3.     * Database
  4.     */
  5.     class Database
  6.     {
  7.         private $hostname   = "localhost";
  8.         private $db_name    = "blog_bio";
  9.         private $username   = "root";
  10.         private $password   = "";
  11.         public $conn;
  12.  
  13.         public function dbConnection()
  14.         {
  15.             $this->conn = null;
  16.             try {
  17.                 $this->conn =new PDO("mysql:host=" . $this->hostname . ";dbname=" . $this->db_name, $this->username, $this->password);
  18.                 $this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  19.             } catch (PDOException $e) {
  20.                 echo "Connection error: " . $e->getMessage();
  21.             }
  22.             return $this->conn;
  23.         }
  24.     }
  25.  ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement