Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.14 KB | None | 0 0
  1. <?php
  2. class Db
  3. {
  4.     public function __construct($host,$user,$pass,$name)
  5.     {
  6.         try
  7.         {
  8.             $this->_connect($host,$user,$pass);
  9.         }catch(Exception $e){
  10.             die($e->getMessage());
  11.         }
  12.  
  13.         try{
  14.             $this->_select($name);
  15.         }catch(Exception $e){
  16.             die($e->getMessage());
  17.         }
  18.     }
  19.  
  20.     private function _connect($host,$user,$pass)
  21.     {
  22.         if(!mysql_connect($host,$user,$pass))
  23.         {
  24.             throw new Exception("Could not connect to database server");
  25.         }else{
  26.             mysql_connect($host,$user,$pass);
  27.         }
  28.     }
  29.  
  30.     private function _select($name)
  31.     {
  32.          if(!mysql_select_db($name))
  33.         {
  34.             throw new Exception("Could not select database");
  35.         }else{
  36.             mysql_select_db($name);
  37.         }
  38.     }
  39.  
  40.     public function query($query)
  41.     {
  42.         return mysql_query($query);
  43.     }
  44.  
  45.     public function fetch($result)
  46.     {
  47.         return mysql_fetch_object($result);
  48.     }
  49.  
  50.     public function escape($str)
  51.     {
  52.         return mysql_real_escape_string($str);
  53.     }
  54. }
  55.  
  56. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement