| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?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) {
- echo $query;
- $stmt = $this->handle->prepare($query);
- $stmt->execute();
- $stmt->close();
- }
- public function updateQuery($query) {
- $stmt = $this->handle->prepare($query);
- if(!$stmt) {
- pa($this->handle);
- } else {
- $stmt->execute();
- $stmt->close();
- }
- }
- public function removeQuery($query) {
- $stmt = $this->handle->prepare($query);
- if(!$stmt) {
- pa($this->handle);
- } else {
- $stmt->execute();
- $stmt->close();
- }
- }
- }
- ?>
|