From 9ba21e6f12f0148aa9fbf5bb60e991230a0490e5 Mon Sep 17 00:00:00 2001 From: TheMrNomis Date: Thu, 12 Nov 2015 11:27:18 +0100 Subject: [PATCH] added 2 database functions to replace deprecated ones --- getEvents.php | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/getEvents.php b/getEvents.php index 5e2770e..33fcf6d 100755 --- a/getEvents.php +++ b/getEvents.php @@ -25,6 +25,53 @@ function connect() } } +/** + * @brief queries all the events from the database + * @param $db: the PDO connection to the database + * @return a list of all the events in the database + */ +function getAllEvents($db) +{ + try + { + $request = $db->prepare('SELECT events.id, events.titre, events.localisation, events.dtstart, events.dtend, events.description FROM events, categorie WHERE events.categorie = categorie.id '); + $request->execute(array('date'=>date("Y-m-d",$date))); + $result = $request->fetchAll(); + $request->closeCursor(); + return $result; + } + catch(PDOException $e) + { + //NOTE: change $e->getMessage() by an error message before going to production + echo($e->getMessage()); + die(); + } +} + +/** + * @brief queries the database for one particular event + * @param $db: the PDO connection to the database + * @param $id: the ID of the event to query + * @return an array containing the event + */ +function getOneEvent($db, $id) +{ + try + { + $request = $db->prepare('SELECT events.id, events.titre, events.localisation, events.dtstart, events.dtend, events.description FROM events, categorie WHERE events.categorie = categorie.id AND events.id = ?'); + $request->execute(array($id)); + $result = $request->fetch(); + $request->closeCursor(); + return $result; + } + catch(PDOException $e) + { + //NOTE: change $e->getMessage() by an error message before going to production + echo($e->getMessage()); + die(); + } +} + /** * @brief queries the database for the events on a certain date * @param $db: the PDO connection to the database