Advertisement
Guest User

Untitled

a guest
Apr 1st, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.71 KB | None | 0 0
  1. <?php // class
  2.  
  3. class Database {
  4.   // connection parameters
  5.   protected $dbtype = 'mysql';
  6.   protected $dbport = 3306;
  7.   protected $dbhost = 'localhost';
  8.   protected $dbuser = 'root';
  9.   protected $dbpass = 'rootpass';
  10.   protected $dbname = 'classes';
  11.  
  12.   public function getpdo() {
  13.       // Build connection string.
  14.       $dsn = sprintf(
  15.         "%s:host=%s;port=%s;dbname=%s",
  16.         $this->dbtype,
  17.         $this->dbhost,
  18.         $this->dbport,
  19.         $this->dbname
  20.       ); // $dsn
  21.       // Connect to database.
  22.       $this->pdo = new PDO($dsn, $this->dbuser, $this->dbpass);
  23.  
  24.       if (!isset($this->pdo)) {die("PDO is not set!");}
  25.     return $this->pdo;
  26.   } // getpdo
  27. } // database
  28.  
  29. // class ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement