function run() { $jsonString = file_get_contents('php://input'); $log_file = 'log'; if (!empty($jsonString)) { $accidentReport = extractReportData($jsonString); $accidentReport->dateTime = getThailandTime(); //save data To MySQL $con = connect(); insertAccidentData($con, $accidentReport); $con->close(); //save data To log file logAccidentReport($log_file, $accidentReport); //respond from server to android $con1 = connect(); $msg = selectMessage($con1, '0000'); $msgJson = packReportAcknowledge($msg); Acknowledge($msgJson); $con1->close(); } }
<?php header('Content-Type: text/html; charset=utf-8'); require_once 'AccidentReport.php'; require_once 'Time.php'; require_once 'logger.php'; function callSaveToLog($data) { $log_file = 'log'; logAccidentReport($log_file, $data); } $dateTime = getThailandTime(); $accidentReport1 = new AccidentReport(1.01, 2.202, 'Test', 10, 20, 0, 'Test Accident1', $dateTime); $accidentReport2 = new AccidentReport(100.001, 10.111, 'Test', 0, 0, 1, 'Test Accident2', $dateTime); $accidentReport3 = new AccidentReport(100.001, 10.111, 'เทสไทย', 0, 0, 1, 'เทสไทย3', $dateTime); callSaveToLog($accidentReport1); callSaveToLog($accidentReport2); callSaveToLog($accidentReport3);