Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $pdo = new PDO(
- "mysql:host=kunet;dbname=db_k1639600",
- "k1639600",
- "papaya",
- [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]
- );
- function loginUser(){
- global $pdo;
- $statement = $pdo->prepare("SELECT * FROM user WHERE username = :username AND password = :password");
- $statement->setFetchMode(PDO::FETCH_ASSOC);
- $statement->bindParam(':username', $_POST['username']);
- $statement->bindParam(':password', $_POST['password']);
- $statement->execute();
- $logf = $statement->fetch(PDO::FETCH_ASSOC);
- return $logf;
- }
- function addUser($user)
- {
- global $pdo;
- $statement = $pdo->prepare('INSERT INTO user
- (username, password) VALUES (?,?)');
- $statement->execute([$user->username,$user->password]);
- }
- function getDest()
- {
- global $pdo;
- $statement = $pdo->prepare('SELECT * FROM flight');
- $statement->execute();
- $result = $statement->fetchAll(PDO::FETCH_CLASS, 'flight');
- return $result;
- }
- function getDestination($destinationAirport)
- {
- if ($destinationAirport == "")
- {
- return getDest();
- }
- global $pdo;
- $statement = $pdo->prepare('SELECT * FROM flight WHERE destinationAirport = ?');
- $statement->execute([$destinationAirport]);
- $stmt = $statement->fetchAll(PDO::FETCH_CLASS, 'flight');
- return $stmt;
- }
- function getDept()
- {
- global $pdo;
- $statement = $pdo->prepare('SELECT * FROM flight');
- $statement->execute();
- $result = $statement->fetchAll(PDO::FETCH_CLASS, 'flight');
- return $result;
- }
- function getDeparture($departureAirport)
- {
- if ($departureAirport == "")
- {
- return getDept();
- }
- global $pdo;
- $statement = $pdo->prepare('SELECT * FROM flight WHERE departureAirport = ?');
- $statement->execute([$departureAirport]);
- $stmt = $statement->fetchAll(PDO::FETCH_CLASS, 'flight');
- return $stmt;
- }
- function getDayz()
- {
- global $pdo;
- $statement = $pdo->prepare('SELECT * FROM flight');
- $statement->execute();
- $result = $statement->fetchAll(PDO::FETCH_CLASS, 'flight');
- return $result;
- }
- function getDay($day)
- {
- if ($day == "")
- {
- return getDayz();
- }
- global $pdo;
- $statement = $pdo->prepare('SELECT * FROM flight WHERE day = ?');
- $statement->execute([$day]);
- $stmt = $statement->fetchAll(PDO::FETCH_CLASS, 'flight');
- return $stmt;
- }
- function getFlightByDeparture($id) {
- global $pdo;
- $statement = $pdo->prepare(
- "SELECT * FROM flight WHERE departureAirport = ?"
- );
- $statement->execute([$id]);
- $result = $statement->fetchAll(PDO::FETCH_CLASS, "flight");
- return $result;
- }
- function getFlightByDay($id) {
- global $pdo;
- $statement = $pdo->prepare(
- "SELECT * FROM flight WHERE day = ?"
- );
- $statement->execute([$id]);
- $result = $statement->fetchAll(PDO::FETCH_CLASS, "flight");
- return $result;
- }
- function getFlightById($id) {
- global $pdo;
- $statement = $pdo->prepare(
- "SELECT * FROM flight WHERE flightID = ?"
- );
- $statement->execute([$id]);
- $result = $statement->fetchAll(PDO::FETCH_CLASS, "flight");
- return $result;
- }
- function getDummyTicket() {
- $flight = new flight();
- $flight->flightID = -1;
- $flight->destinationAirport = "Insert Departure Airport";
- $flight->departureAirport = "Insert Destination Airport";
- $flight->departureTime = "00:00:00";
- $flight->arrivalTime = "00:00:00";
- $flight->day = "Insert day of the week";
- $flight->price = "00.00";
- $flight->domestic = "0";
- return $flight;
- }
- function getFlightByDestination()
- {
- global $pdo;
- $statement = $pdo->prepare("SELECT * FROM flight WHERE destinationAirport = :destinationAirport");
- $statement->bindParam(':destinationAirport', $_POST['destinationAirport']);
- $result = $statement->fetchAll(PDO::FETCH_CLASS, 'flight');
- return $result;
- }
- function addToCart($dest)
- {
- global $pdo;
- $statement = $pdo->prepare('INSERT INTO cart (flightID, totalPrice)
- VALUES (:flightID, :totalPrice)
- ON DUPLICATE KEY UPDATE flightID=:flightID, totalPrice=:totalPrice');
- $statement->bindParam(':flightID', $_POST['flightID'], PDO::PARAM_INT);
- $statement->bindParam(':totalPrice', $_POST['totalPrice'], PDO::PARAM_STR);
- $statement->execute();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement