database.inc.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. class Database {
  3. private $handle = null;
  4. public function __construct($host, $user, $password, $db) {
  5. $this->handle = new mysqli($host, $user, $password, $db);
  6. }
  7. public function close() {
  8. $this->handle->Close();
  9. }
  10. public function SelectQuery($query) {
  11. $stmt = $this->handle->query($query);
  12. if($stmt) {
  13. if($stmt->num_rows == 0) {
  14. $result = NULL;
  15. } else {
  16. $result = array();
  17. while($res = $stmt->fetch_object()) {
  18. $result[] = $res;
  19. }
  20. }
  21. } else {
  22. return null;
  23. }
  24. /*
  25. elseif($stmt->num_rows == 1) {
  26. $result = $stmt->fetch_object();
  27. }
  28. */
  29. $stmt->close();
  30. return $result;
  31. }
  32. public function insertQuery($query) {
  33. $stmt = $this->handle->prepare($query);
  34. $stmt->execute();
  35. $stmt->close();
  36. }
  37. public function updateQuery($query) {
  38. $stmt = $this->handle->prepare($query);
  39. if(!$stmt) {
  40. pa($this->handle);
  41. } else {
  42. $stmt->execute();
  43. $stmt->close();
  44. }
  45. }
  46. public function removeQuery($query) {
  47. $stmt = $this->handle->prepare($query);
  48. if(!$stmt) {
  49. pa($this->handle);
  50. } else {
  51. $stmt->execute();
  52. $stmt->close();
  53. }
  54. }
  55. }
  56. ?>