database.inc.php 772 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. }
  38. ?>