I am trying to get data from json file , parse it and add data from it to database. I am using as database, oracle. I am getting the errors :
This is my JSON file
{
"data": {
"gps": [
{ "location": "45.778123,24.151165"
},
{ "location": "45.7875116,24.1549801"
}
]
}
This is my php file
<?php
$file = 'JSONdata.json';
$json = file_get_contents($file,0,null,null);
$obj = json_decode($json,true);
$data = $obj->data->gps;
include 'connection.php';
function insert_data($connname, $conn)
{
foreach ($data as $post) {
$stmt = oci_parse($conn, "insert into GPSLOGS
values('".$post->location."')");
oci_execute($stmt, OCI_DEFAULT);
echo "$connname inserted row without committing<br>\n";
}
}
insert_data('c1', $conn);
?>
Do you know what am I doing wrong? And why it keeps getting those errors? I also tried using another format of JSON file and parse it differently , but it keeps getting the same errors.
.json
[{ "gps": "45.778123,24.151165"},{"gps": "45.7875116,24.1549801"}]
.php
$file = 'JSONdata.json';
$json = file_get_contents($file,0,null,null);
$obj = json_decode($json,true);
foreach($obj as $item)
{ echo $item['gps'];}
