Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include 'functions.php';
- $function=getParameter('function');
- $ident=getParameter('ident');
- $history=getParameter('history');
- $servername = "10.1.1.12";
- $username = "root";
- $password = "donc3910";
- $dbname = "TRACKER";
- $conn = mysqli_connect($servername, $username, $password, $dbname); // Create connection
- if ($conn->connect_error) { // Check connection
- die("Connection failed: " . $conn->connect_error);
- exit;
- }
- if ($function=="getQuery") { getQuery($ident); }
- if ($function=="getHistory") { getHistory($ident,$history); }
- function resultToArray($result) {
- $rows = array();
- while($row = $result->fetch_assoc()) {
- $rows[] = $row;
- }
- return $rows;
- }
- function getQuery($ident) {
- global $conn;
- $sql = "SELECT * FROM UNIT_TEMPLATE WHERE UNITID = '$ident' ORDER BY TIME DESC LIMIT 1";
- if (!$result = $conn->query($sql)) {
- echo "Sorry, the website is experiencing problems.";
- exit;
- }
- if ($result->num_rows === 0) {
- echo "NOT registered";
- exit;
- }
- $client = $result->fetch_assoc();
- $result->free();
- echo json_encode($client);
- }
- function getHistory($ident,$history) {
- global $conn;
- $sql = "SELECT LATITUDE, LONGITUDE, SPEED FROM UNIT_TEMPLATE WHERE UNITID = '$ident' ORDER BY TIME DESC LIMIT $history";
- if (!$result = $conn->query($sql)) {
- echo "Sorry, the website is experiencing problems.";
- exit;
- }
- if ($result->num_rows === 0) {
- echo "NOT registered";
- exit;
- }
- $rows = resultToArray($result);
- $result->free();
- $content = json_encode($rows);
- $length = strlen($content);
- echo $content;
- }
- function trial() {
- echo 'HELLO';
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement