Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.16 KB | None | 0 0
  1. <?php
  2.  
  3. final class MySQL
  4. {
  5.     private static $instance;
  6.  
  7.     public $db_count = 0;
  8.  
  9.     public $db_link;
  10.  
  11.     private function __construct()
  12.     {
  13.         $this->db_link = new mysqli(BD_HOST, BD_USER, BD_PASS, BD_NAME, 3306);
  14.  
  15.         if ($this->db_link->connect_error) {
  16.             exit();
  17.         }
  18.  
  19.         $this->db_link->set_charset("utf8");
  20.     }
  21.  
  22.     public static function getInstance()
  23.     {
  24.         if (self::$instance === null) {
  25.             self::$instance = new self();
  26.         }
  27.  
  28.         return self::$instance;
  29.     }
  30.  
  31.     public function query($sql)
  32.     {
  33.         $query = $this->db_link->query($sql);
  34.  
  35.         $this->db_count += 1;
  36.  
  37.         if ($this->db_link->error) {
  38.             exit($this->db_link->error);
  39.         }
  40.  
  41.         return $query;
  42.     }
  43.  
  44.     private function fetch_assoc($result)
  45.     {
  46.         return $result->fetch_assoc();
  47.     }
  48.  
  49.     public function insert_id()
  50.     {
  51.         return $this->db_link->insert_id;
  52.     }
  53.  
  54.     private function num_rows($result)
  55.     {
  56.         return $result->num_rows;
  57.     }
  58.  
  59.     public function __destruct()
  60.     {
  61.         $this->db_link->close();
  62.     }
  63. }
  64.  
  65. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement