Guest User

Untitled

a guest
Jan 22nd, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. <?php
  2.  
  3. define("DEBUG", true);
  4.  
  5. class db {
  6. private $db;
  7. private $instance;
  8. private $debug;
  9.  
  10. private function __constructor($debug) {
  11. $this->debug = $debug;
  12. $this->db = new mysqli('123.45.56.67', 'username',
  13. 'password', 'tablename'); //Where 123.45.56.67' is the ip of the
  14. database
  15. }
  16.  
  17. public static function instance($debug = DEBUG) {
  18. if(!self::$instance) {
  19. $className = __CLASS__;
  20. self::$instance = new $className($debug);
  21. }
  22. return self::$instance;
  23. }
  24.  
  25. /**
  26. * Generic select function. <br>
  27. */
  28. public function select($query) {
  29. $result = $this->db->query($query);
  30. flush();
  31. return $result;
  32. }
  33.  
  34. /**
  35. * Generic update function. <br>
  36. * If debug is true, it doesn't update. <br>
  37. */
  38. public function update($query) {
  39. if($this->debug) {
  40. print $query;
  41. return true;
  42. } else {
  43. $result = $this->db->query($query);
  44. flush();
  45. return $result;
  46. }
  47. }
  48. }
  49. ?>
Add Comment
Please, Sign In to add comment