Example #1
0
 public static function get_comments_by_goal_id($goal_id)
 {
     $dbObject = new Database();
     $db = $dbObject->connect_to_database(DB_HOST, DB_PORT, DB_NAME, DB_USER, DB_PASS);
     $query = "SELECT * from comments WHERE cmmnt_goal={$goal_id}";
     $goalComments = $db->prepare($query);
     $goalComments->execute();
     return $goalComments;
 }
Example #2
0
 public static function save_user($User)
 {
     $dbObject = new Database();
     $db = $dbObject->connect_to_database(DB_HOST, DB_PORT, DB_NAME, DB_USER, DB_PASS);
     $query = "INSERT INTO users (email, password, firstName, lastName) VALUES ( :email, :password, :firstName, :lastName)";
     $addUser = $db->prepare($query);
     $addUser->bindParam(":email", $User->email, PDO::PARAM_STR);
     $addUser->bindParam(":password", $User->password, PDO::PARAM_STR);
     $addUser->bindParam(":firstName", $User->firstName, PDO::PARAM_STR);
     $addUser->bindParam(":lastName", $User->lastName, PDO::PARAM_STR);
     $addUser->execute();
     $db = null;
 }
Example #3
0
 public static function check_if_user_exists($User)
 {
     $dbObject = new Database();
     $db = $dbObject->connect_to_database(DB_HOST, DB_PORT, DB_NAME, DB_USER, DB_PASS);
     $query = "SELECT * FROM users WHERE email=:email";
     $checkUser = $db->prepare($query);
     $checkUser->bindParam(":email", $User->email, PDO::PARAM_STR);
     $checkUser->execute();
     $allRows = $checkUser->fetchAll();
     $rowCount = count($allRows);
     if ($rowCount) {
         return true;
     }
     $db = null;
 }
Example #4
0
 public static function echo_all_goals_json()
 {
     $dbObject = new Database();
     $db = $dbObject->connect_to_database(DB_HOST, DB_PORT, DB_NAME, DB_USER, DB_PASS);
     if (!isset($_SESSION)) {
         session_start();
     }
     $query = "SELECT * from goals";
     $GoalsDB = $db->prepare($query);
     $GoalsDB->execute();
     $Goals = array();
     while ($Goal = $GoalsDB->fetch(PDO::FETCH_ASSOC)) {
         array_push($Goals, $Goal);
     }
     echo json_encode($Goals);
 }
Example #5
0
<?php

include_once 'mysql.php';
header('Content-type: application/json');
$action = $_GET['action'];
$mode = $_GET['mode'];
$link = Database::connect_to_database();
if ($action == "bus_line") {
    if ($mode == "") {
        $sql = "SELECT `id`,UNIX_TIMESTAMP(`update_time`) as `update_time`, `starting_point`, `progress` \n    \t\t\t\tFROM `bus_line` ORDER BY `update_time` DESC limit 5";
        $result = mysql_query($sql, $link);
        $bus_lines = array();
        while ($row = mysql_fetch_assoc($result)) {
            $json_row = array();
            $json_row['id'] = (int) $row['id'];
            $json_row['starting_point'] = (int) $row['starting_point'];
            $json_row['update_time'] = (int) $row['update_time'];
            $json_row['progress'] = (int) $row['progress'];
            array_push($bus_lines, $json_row);
        }
        echo json_encode($bus_lines);
    } else {
        if ($mode == "add") {
            $starting_point = $_GET['starting_point'];
            $progress = $_GET['progress'];
            $sql = "INSERT INTO `bus_line` (`update_time`, `starting_point`, `progress`) VALUES (now(), {$starting_point}, {$progress})";
            Database::execute($sql, $link);
            if (mysql_affected_rows($link) > 0) {
                $json['status'] = "success";
                $json['id'] = mysql_insert_id();
                echo json_encode($json);