Advertisement
benshepherd

DB Class

Jun 6th, 2013
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.65 KB | None | 0 0
  1. <?php
  2.     class DB
  3.     {
  4.         private $instance;
  5.        
  6.         function __construct() {
  7.             $this->instance = new MySQLi("localhost","root","password","database");
  8.             if($this->instance->connect_errno) {
  9.                 die("MySQL Error: " . $this->instance->connect_error . "<br />");  
  10.             }
  11.         }
  12.        
  13.         public function Query($q) {
  14.             return $this->instance->query($q); 
  15.         }
  16.        
  17.         public function TableExists($table) {
  18.             $res = $this->Query("SHOW TABLES LIKE '$table'");
  19.             return $res->num_rows > 0;
  20.         }
  21.        
  22.         public function LastError() {
  23.             return $this->instance->error; 
  24.         }
  25.        
  26.         public function Escape($v) {
  27.             return $this->instance->real_escape_string($v);
  28.         }
  29.     }
  30. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement