Hi folks
I am trying to parse JSON data
example is
{"event":"cellData","data":"MCC:111, MNC: 11, LAC:53a9, CI:74c1, BSIC:0b,
Arfcn:00111, Arfcn_ded:INVALID_ARFCN","published_at":"2019-05-09T10:58:20.970Z",
"coreid":"11111111111111111111111"}
The data will be sent from Electron via webhook to my php script on my server. PHP script will parse it and append a record line to a growing MySQL database.
I am new in Particle/PHP and try to avoid obvious errors at the beginning. I have seen some similar topics but could you please skim over my php code prototype and point out what is wrong and missing?
<?php
$json=$_POST;
//not sure of this return product and how to address elements of it correctly
$data=json_decode($json, true);
/* for debugging json decoding
var_dump($data);
*/
//should be careful with putting this in php explicitly - see methods of hiding it
$hostname="localhost";
$username="user";
$password="password";
$db="TESTDB";
$dbconnect=mysqli_connect($hostname,$username, $password,$db);
if ($dbconnect->connect_error) {
die("Database connection failed:" . $dbconnect->connect_error);
}
//not sure that this is correct way to address to elements of parsed array
$mcc=$data['MCC'];
$mnc=$data['MNCC'];
$lac=$data['LAC'];
$ci=$data['CI'];
$bsic=$data['BSIC'];
//need to think how to convert it correctly - see tips in the folder
$ts=$data['published_at'];
$query="INSERT INTO MyTest (mcc, mnc, lac, ci, bsic, ts)
VALUE ('$mcc', '$mnc', '$lac', '$ci', '$ci', '$bsic', '$ts')";
if (!mysqli_query($dbconnect, $query)){
die('An error occured.');
}
else{
echo "Success!";
}
// should I disconnect it here from db?
?>
Rickkas7 kindly published tutorial for working with Google Firebase
but I would like to use my own server.
Thanks for your feedback and apologies if I have missed some identical threads!