$queryQL = ‘SELECT co FROM “Test”.“autogen”.“airSensors” WHERE time > now()-3d’;
$result = $queryApi->query($queryQL);
"PHP Fatal error: Uncaught InfluxDB2\ApiException: [400] Error connecting to the API (http://localhost:8086/api/v2/query?org=xxx)(compilation failed: error @1:16-1:17: invalid statement: \
error @1:17-1:73: got unexpected token in string expression @1:73-1:73: EOF) in /var/www/html/Test/vendor/influxdata/influxdb-client-php/src/InfluxDB2/DefaultApi.php:164
Stack trace: #0 /var/www/html/Test/vendor/influxdata/influxdb-client-php/src/InfluxDB2/DefaultApi.php(221): InfluxDB2\DefaultApi->sendRequest() #1 /var/www/html/Test/vendor/influxdata/influxdb-client-php/src/InfluxDB2/DefaultApi.php(79): InfluxDB2\DefaultApi->request() #2 /var/www/html/Test/vendor/influxdata/influxdb-client-php/src/InfluxDB2/QueryApi.php(115): InfluxDB2\DefaultApi->post() #3 /var/www/html/Test/vendor/influxdata/influxdb-client-php/src/InfluxDB2/QueryApi.php(67): InfluxDB2\QueryApi->postQuery() #4 /var/www/html/Test/Test_ql.php(69): InfluxDB2\QueryApi->query() #5 {main}
thrown in /var/www/html/Test/vendor/influxdata/influxdb-client-php/src/InfluxDB2/DefaultApi.php on line 164"
But this works fine with curl (influxql) and flux
$curl --get http://localhost:8086/query?db=Test
–header “Authorization: ”
–data-urlencode “q=SELECT co FROM "Test"."autogen"."airSensors" WHERE time > now()-3d”
It appears to be a parsing issue in PHP. Try using double quotes for the string boundaries and then escape the double quotes inside the string:
$queryApi = $client->createQueryApi();
$queryQL = "SELECT co FROM \"Test\".\"autogen\".\"airSensors\" WHERE time > now()-3d";
$result = $queryApi->query($queryQL);
Ah, alright. I was thinking the InfluxDB v2 PHP client supported InfluxQL, but it doesn’t. It only supports Flux. You need to use the InfluxDB v1 PHP client. InfluxDB v2 includes a v1 compatibility API, so the v1 PHP client should work with InfluxDB v2.