Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- final class MySQL
- {
- private static $instance;
- public $db_count = 0;
- public $db_link;
- private function __construct()
- {
- $this->db_link = new mysqli(BD_HOST, BD_USER, BD_PASS, BD_NAME, 3306);
- if ($this->db_link->connect_error) {
- exit();
- }
- $this->db_link->set_charset("utf8");
- }
- public static function getInstance()
- {
- if (self::$instance === null) {
- self::$instance = new self();
- }
- return self::$instance;
- }
- public function query($sql)
- {
- $query = $this->db_link->query($sql);
- $this->db_count += 1;
- if ($this->db_link->error) {
- exit($this->db_link->error);
- }
- return $query;
- }
- private function fetch_assoc($result)
- {
- return $result->fetch_assoc();
- }
- public function insert_id()
- {
- return $this->db_link->insert_id;
- }
- private function num_rows($result)
- {
- return $result->num_rows;
- }
- public function __destruct()
- {
- $this->db_link->close();
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement