InfluxDB PHP

Install Influxdb, and start it. After start we should create user After we should edit influx config file on CentOS /etc/influxdb/influxdb.conf Find and replace volumes in http section restart influx db Now in php to insert data

$q = "test,city=".$city." population=87879879 \n";
 
$ch = curl_init();
 
curl_setopt($ch, CURLOPT_URL, "http://127.0.0.1:8086/write?db=databasename&u=username&p=password");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, substr($q, 0, -1));
curl_setopt($ch, CURLOPT_POST, 1);
 
$headers = array();
$headers[] = "Content-Type: application/x-www-form-urlencoded";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
 
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);

To read data from database

$query = "<strong>SELECT * FROM test</strong>";
 
$ch = curl_init();
$query = urlencode($q);
curl_setopt($ch, CURLOPT_URL, "http://localhost:8086/query?db=database&amp;u=username&amp;p=password&amp;q=" . $query);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 0);
 
$headers = array();
$headers[] = "Content-Type: application/x-www-form-urlencoded";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
 
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
 
//display array
print_r(json_decode($result, true));

make sure you have changed database,username,password