Advertisement
Guest User

dbConnect

a guest
Apr 9th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.15 KB | None | 0 0
  1. <?php
  2. $pdo = new PDO(
  3.   "mysql:host=kunet;dbname=db_k1639600",
  4.   "k1639600",
  5.   "papaya",
  6.   [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]
  7. );
  8.  
  9. function loginUser(){
  10.   global $pdo;
  11.   $statement = $pdo->prepare("SELECT * FROM user WHERE username = :username AND password = :password");
  12.   $statement->setFetchMode(PDO::FETCH_ASSOC);
  13.   $statement->bindParam(':username', $_POST['username']);
  14.   $statement->bindParam(':password', $_POST['password']);
  15.   $statement->execute();
  16.   $logf = $statement->fetch(PDO::FETCH_ASSOC);
  17.   return $logf;
  18. }
  19.  
  20. function addUser($user)
  21. {
  22.   global $pdo;
  23.   $statement = $pdo->prepare('INSERT INTO user
  24.    (username, password) VALUES (?,?)');
  25.   $statement->execute([$user->username,$user->password]);
  26. }
  27.  
  28.  
  29. function getDest()
  30. {
  31.   global $pdo;
  32.   $statement = $pdo->prepare('SELECT * FROM flight');
  33.   $statement->execute();
  34.   $result = $statement->fetchAll(PDO::FETCH_CLASS, 'flight');
  35.   return $result;
  36. }
  37.  
  38. function getDestination($destinationAirport)
  39. {
  40.   if ($destinationAirport == "")
  41.   {
  42.     return getDest();
  43.   }
  44.   global $pdo;
  45.   $statement = $pdo->prepare('SELECT * FROM flight WHERE destinationAirport = ?');
  46.   $statement->execute([$destinationAirport]);
  47.   $stmt = $statement->fetchAll(PDO::FETCH_CLASS, 'flight');
  48.   return $stmt;
  49. }
  50.  
  51. function getDept()
  52. {
  53.   global $pdo;
  54.   $statement = $pdo->prepare('SELECT * FROM flight');
  55.   $statement->execute();
  56.   $result = $statement->fetchAll(PDO::FETCH_CLASS, 'flight');
  57.   return $result;
  58. }
  59.  
  60. function getDeparture($departureAirport)
  61. {
  62.   if ($departureAirport == "")
  63.   {
  64.     return getDept();
  65.   }
  66.   global $pdo;
  67.   $statement = $pdo->prepare('SELECT * FROM flight WHERE departureAirport = ?');
  68.   $statement->execute([$departureAirport]);
  69.   $stmt = $statement->fetchAll(PDO::FETCH_CLASS, 'flight');
  70.   return $stmt;
  71. }
  72.  
  73. function getDayz()
  74. {
  75.   global $pdo;
  76.   $statement = $pdo->prepare('SELECT * FROM flight');
  77.   $statement->execute();
  78.   $result = $statement->fetchAll(PDO::FETCH_CLASS, 'flight');
  79.   return $result;
  80. }
  81.  
  82. function getDay($day)
  83. {
  84.   if ($day == "")
  85.   {
  86.     return getDayz();
  87.   }
  88.   global $pdo;
  89.   $statement = $pdo->prepare('SELECT * FROM flight WHERE day = ?');
  90.   $statement->execute([$day]);
  91.   $stmt = $statement->fetchAll(PDO::FETCH_CLASS, 'flight');
  92.   return $stmt;
  93. }
  94.  
  95. function getFlightByDeparture($id) {
  96.   global $pdo;
  97.   $statement = $pdo->prepare(
  98.     "SELECT * FROM flight WHERE departureAirport = ?"
  99.   );
  100.   $statement->execute([$id]);
  101.   $result = $statement->fetchAll(PDO::FETCH_CLASS, "flight");
  102.   return $result;
  103. }
  104.  
  105.  
  106. function getFlightByDay($id) {
  107.   global $pdo;
  108.   $statement = $pdo->prepare(
  109.     "SELECT * FROM flight WHERE day = ?"
  110.   );
  111.   $statement->execute([$id]);
  112.   $result = $statement->fetchAll(PDO::FETCH_CLASS, "flight");
  113.   return $result;
  114. }
  115.  
  116. function getFlightById($id) {
  117.   global $pdo;
  118.   $statement = $pdo->prepare(
  119.     "SELECT * FROM flight WHERE flightID = ?"
  120.   );
  121.   $statement->execute([$id]);
  122.   $result = $statement->fetchAll(PDO::FETCH_CLASS, "flight");
  123.   return $result;
  124. }
  125.  
  126. function getDummyTicket() {
  127.   $flight = new flight();
  128.   $flight->flightID = -1;
  129.   $flight->destinationAirport = "Insert Departure Airport";
  130.   $flight->departureAirport = "Insert Destination Airport";
  131.   $flight->departureTime = "00:00:00";
  132.   $flight->arrivalTime = "00:00:00";
  133.   $flight->day = "Insert day of the week";
  134.   $flight->price = "00.00";
  135.   $flight->domestic = "0";
  136.   return $flight;
  137. }
  138.  
  139. function getFlightByDestination()
  140. {
  141.   global $pdo;
  142.   $statement = $pdo->prepare("SELECT * FROM flight WHERE destinationAirport = :destinationAirport");
  143.   $statement->bindParam(':destinationAirport', $_POST['destinationAirport']);
  144.   $result = $statement->fetchAll(PDO::FETCH_CLASS, 'flight');
  145.   return $result;
  146. }
  147.  
  148.  
  149.  
  150. function addToCart($dest)
  151. {
  152.   global $pdo;
  153.   $statement = $pdo->prepare('INSERT INTO cart (flightID, totalPrice)
  154.    VALUES (:flightID, :totalPrice)
  155.  
  156.    ON DUPLICATE KEY UPDATE flightID=:flightID, totalPrice=:totalPrice');
  157.  
  158.     $statement->bindParam(':flightID', $_POST['flightID'], PDO::PARAM_INT);
  159.     $statement->bindParam(':totalPrice', $_POST['totalPrice'], PDO::PARAM_STR);
  160.     $statement->execute();
  161. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement