Advertisement
Guest User

Untitled

a guest
Aug 2nd, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.84 KB | None | 0 0
  1. <?php
  2.     include 'functions.php';
  3.  
  4.         $function=getParameter('function');
  5.     $ident=getParameter('ident');
  6.     $history=getParameter('history');
  7.    
  8.     $servername = "10.1.1.12";
  9.     $username = "root";
  10.     $password = "donc3910";
  11.     $dbname = "TRACKER";
  12.     $conn = mysqli_connect($servername, $username, $password, $dbname); // Create connection
  13.  
  14.     if ($conn->connect_error) { // Check connection
  15.         die("Connection failed: " . $conn->connect_error);
  16.         exit;
  17.     }
  18.    
  19.     if ($function=="getQuery") { getQuery($ident); }
  20.     if ($function=="getHistory") { getHistory($ident,$history); }
  21.    
  22.     function resultToArray($result) {
  23.             $rows = array();
  24.             while($row = $result->fetch_assoc()) {
  25.                 $rows[] = $row;
  26.             }
  27.         return $rows;
  28.         }
  29.         function getQuery($ident) {
  30.         global $conn;
  31.         $sql = "SELECT * FROM UNIT_TEMPLATE WHERE UNITID = '$ident' ORDER BY TIME DESC LIMIT 1";
  32.         if (!$result = $conn->query($sql)) {
  33.             echo "Sorry, the website is experiencing problems.";
  34.             exit;
  35.         }
  36.         if ($result->num_rows === 0) {
  37.             echo "NOT registered";
  38.             exit;
  39.         }
  40.         $client = $result->fetch_assoc();
  41.         $result->free();
  42.                 echo json_encode($client);
  43.         }
  44.     function getHistory($ident,$history) {
  45.         global $conn;
  46.         $sql = "SELECT LATITUDE, LONGITUDE, SPEED FROM UNIT_TEMPLATE WHERE UNITID = '$ident' ORDER BY TIME DESC LIMIT $history";
  47.         if (!$result = $conn->query($sql)) {
  48.             echo "Sorry, the website is experiencing problems.";
  49.             exit;
  50.         }
  51.         if ($result->num_rows === 0) {
  52.             echo "NOT registered";
  53.             exit;
  54.         }
  55.         $rows = resultToArray($result);
  56.                 $result->free();
  57.                
  58.                 $content = json_encode($rows);
  59.                 $length = strlen($content);
  60.                 echo $content;
  61.                
  62.                 }
  63.     function trial() {
  64.         echo 'HELLO';
  65.     }
  66. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement