Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2016
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.80 KB | None | 0 0
  1.     class Database{
  2.         private $db;
  3.        
  4.         const sql_host = "localhost";
  5.         const sql_base = "tetbase";
  6.         const sql_user = "root";
  7.         const sql_pass = "";
  8.        
  9.         public function __construct() {
  10.             $mysqli = @new mysqli(self::sql_host, self::sql_user, self::sql_pass, self::sql_base);
  11.             if(!$mysqli->connect_error) {
  12.                 $this->db = $mysqli;
  13.                 $this->db->query("SET NAMES 'utf8'");
  14.                 return $this->db;
  15.             } else exit("<strong>[Error]</strong> MySQL connection failed");
  16.         }
  17.        
  18.         public function query($sql) {
  19.             return $this->db->query($sql);
  20.         }
  21.        
  22.         public function assoc($result) {
  23.             if(!empty($result)) {  
  24.                 return $result->fetch_assoc();
  25.             } else return false;
  26.         }
  27.        
  28.         public function num_rows($query) {
  29.             if(!empty($query)) {
  30.                 return $query->num_rows;
  31.             } else return false;
  32.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement