MySqliWrapper.inc 837 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. class MySqliWrapper
  3. {
  4. public static $instance;
  5. public static function getInstance()
  6. {
  7. if(!MySqliWrapper::$instance)
  8. {
  9. MySqliWrapper::$instance = new MySqliWrapper();
  10. }
  11. return MySqliWrapper::$instance;
  12. }
  13. private $mysqli;
  14. private function __construct()
  15. {
  16. $this->mysqli = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_DATABASE);
  17. }
  18. public function get($key)
  19. {
  20. $result = $this->mysqli->query($key);
  21. if($result)
  22. {
  23. $data = array();
  24. while ($row = $result->fetch_assoc())
  25. {
  26. $data[] = $row;
  27. }
  28. if(count($data) == 1)
  29. {
  30. return $data;
  31. }
  32. return $data;
  33. }
  34. return false;
  35. }
  36. public function add($key, $value)
  37. {
  38. $this->mysqli->query($key);
  39. }
  40. public function set($key, $value)
  41. {
  42. $this->mysqli->query($key);
  43. }
  44. public function delete($key)
  45. {
  46. $this->mysqli->query($key);
  47. }
  48. }