| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?php
- class Database {
- private $handle = null;
- public function __construct($host, $user, $password, $db) {
- $this->handle = new mysqli($host, $user, $password, $db);
- }
- public function close() {
- $this->handle->Close();
- }
- public function selectQuery($query) {
- $stmt = $this->handle->query($query);
- if($stmt) {
- if($stmt->num_rows == 0) {
- $result = NULL;
- } else {
- $result = array();
- while($res = $stmt->fetch_object()) {
- $result[] = $res;
- }
- }
- } else {
- return null;
- }
- /*
- elseif($stmt->num_rows == 1) {
- $result = $stmt->fetch_object();
- }
- */
- $stmt->close();
- return $result;
- }
- public function selectStringQuery($query) {
- $stmt = $this->handle->query($query);
- if($stmt) {
- if($stmt->num_rows == 0) {
- $result = NULL;
- } else {
- $result = $res = $stmt->fetch_array();
- }
- } else {
- return null;
- }
- /*
- elseif($stmt->num_rows == 1) {
- $result = $stmt->fetch_object();
- }
- */
- $stmt->close();
- return $result[0];
- }
- public function insertQuery($query) {
- $stmt = $this->handle->prepare($query);
- $stmt->execute();
- $stmt->close();
- }
- public function updateQuery($query) {
- $stmt = $this->handle->prepare($query);
- if(!$stmt) {
- pa($this->handle); // TODO: better error
- } else {
- $stmt->execute();
- $stmt->close();
- }
- }
- public function removeQuery($query) {
- $stmt = $this->handle->prepare($query);
- if(!$stmt) {
- pa($this->handle);
- } else {
- $stmt->execute();
- $stmt->close();
- }
- }
- }
- ?>
|