0
I am trying to send data from my database to a . json file but I am not able to because it creates the file and nothing appears, only the empty array.
my code is as follows::
<?php
$connect = mysqli_connect("localhost","root","admin","opcuaserver");
$query = "SELECT * FROM sensores (Timestamp, Metros, LM335, LM35)";
$result = mysqli_query($connect, $query);
$data = array();
$data[$result] = array();
//format the data
$formattedData = json_encode($data);
//set the filename
$filename = 'basedadossensores.json';
//open or create the file
$handle = fopen($filename,'w+');
//write the data into the file
fwrite($handle,$formattedData);
//close the file
fclose($handle);
?>
and the result when I run the code
{"Values->":[]}
The $result returns what ?
– Bulfaitelo
I want to return the values that are in the database
– Sergio Nunes
yes but now it is returning what ? if you run this query directly in the database it returns what ?
– Bulfaitelo
at this point when I run the file it gets connected in my database and shows nothing I’m trying to go by creating an array but I think I’m fooling myself in his programming
– Sergio Nunes
Let me query
SELECT * FROM sensores (Timestamp, Metros, LM335, LM35)
what are these meters, LM335 ?– Bulfaitelo