Advertisement
Guest User

Untitled

a guest
Jul 5th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.20 KB | None | 0 0
  1. class Mysql_DB
  2. {
  3.   private
  4.     $host = 'localhost',
  5.     $port = ,
  6.     $dbname = '',
  7.     $user = '',
  8.     $password = '';
  9.   protected
  10.     $handler,
  11.     $base;
  12.   private static
  13.     $instance = null;
  14.  
  15.   private function __construct()
  16.   {
  17.     $this->handler = mysql_connect($this->host.':'.$this->port, $this->user, $this->password) or die('Could not connect: ' . mysql_error());
  18.     mysql_query("SET NAMES utf8");
  19.     $this->base = mysql_select_db($this->dbname, $this->handler) or die('Could not select db: ' . mysql_error());
  20.   }
  21.  
  22.   public function query($query)
  23.   {
  24.     return mysql_query($query, $this->handler);
  25.   }
  26.  
  27.   public function hasResult($query)
  28.   {
  29.     $result = mysql_num_rows( $this->query($query) );
  30.     return ($result > 0 ) ? true : false;
  31.   }
  32.  
  33.   public function getArray($query)
  34.   {
  35.     $array = array();
  36.     $result = $this->query($query);
  37.     while ( $row = mysql_fetch_assoc( $result ) )
  38.     {
  39.       $array[] = $row;
  40.     }
  41.     return $array;
  42.   }
  43.  
  44.   public function getOne($query)
  45.   {
  46.     return mysql_fetch_assoc ( $this->query($query) );
  47.   }
  48.  
  49.   public static function getInstance()
  50.   {
  51.     if( self::$instance == null )
  52.     {
  53.       self::$instance = new Mysql_DB();
  54.     }
  55.     return self::$instance;
  56.   }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement