Differences

This shows you the differences between two versions of the page.

Link to this comparison view

proc_help_garage [2012-11-29 14:09]
Joakim Forsgren created
proc_help_garage [2017-09-01 14:54]
Line 1: Line 1:
-====== Hjälp ====== 
  
- 
-<code php> 
-<?php 
-class Garage extends mysqli { 
- 
-  public function __construct($settings) { 
-    parent::__construct($settings['HostName'],$settings['UserName'], $settings['Password'],$settings['DatabaseName']); 
-    if ($this->connect_errno) { 
-      echo "Failed to connect to MySQL: (" . $this->connect_errno . ") " . $this->connect_error; 
-      exit; 
-    } 
-    $query = "SET NAMES utf8"; 
-    $this->query($query); 
-  } 
-   
-  public function parkVehicle($vehicle) { 
-    $query ="INSERT INTO  `Garage` (`ObjectData`) VALUES ('" . serialize($vehicle) . "')"; 
-    $this->query($query); 
-  } 
-   
-  public function checkoutVehicle($reg_id) { 
-    // Hämta alla från databasen 
-    $query = "SELECT * FROM Garage"; 
-    $result = $this->query($query); 
-    while ($row = $result->fetch_assoc()) { 
-      // unserilize 
-      $object = unserialize($row['ObjectData']); 
-      // jämför regid om reg_id är rätt 
-      if ($reg_id == $object->getRegistration()) { 
-        // Ta bort från databas 
-        $query = "DELETE FROM `Garage` WHERE `VehicleID` = '" . $row['VehicleID'] . "'"; 
-        $this->query($query); 
-        // retunera objektet 
-        return $object; 
-      } 
-    } 
-  } 
- 
-} 
- 
-</code>