database.inc.php 570 B

1234567891011121314151617181920212223242526272829303132333435
  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 query($query) {
  11. $stmt = $this->handle->query($query);
  12. if($stmt->num_rows == 0) {
  13. $result = NULL;
  14. } else {
  15. $result = array();
  16. while($res = $stmt->fetch_object()) {
  17. $result[] = $res;
  18. }
  19. }
  20. /*
  21. elseif($stmt->num_rows == 1) {
  22. $result = $stmt->fetch_object();
  23. }
  24. */
  25. return $result;
  26. }
  27. }
  28. ?>