Advertisement
Guest User

db class

a guest
Mar 4th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.72 KB | None | 0 0
  1. <?php
  2.  
  3. class database {
  4.  
  5.     private $hostname = '127.0.0.1';
  6.     private $username = 'root';
  7.     private $password = '************';
  8.     private $database = 'womj';
  9.     private $connection = null;
  10.  
  11.     public function __construct() {
  12.         try {
  13.             $this->connection = new PDO('mysql://' . $this->hostname . '/' . $this->database, $this->username, $this->password);
  14.         } catch (PDOException $ex) {
  15.             exit($ex->getMessage());
  16.         }
  17.     }
  18.  
  19.     public function fetchResults($query) {
  20.         $stmt = $this->connection->prepare($query);
  21.         $params = array_splice(func_get_args(), 1);
  22.  
  23.         $stmt->execute($params);
  24.  
  25.         return $stmt->fetchAll(PDO::FETCH_OBJ);
  26.     }
  27.  
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement