Reputation: 51
I am trying to connect influxDB with PHP and i can say i was almost successful all thanks to Corley for developing PHP api. I am finding difficult to set the database on which my query has to be applied.
Below is the sample PHP code I am working on, How to choose the specific database from the available list of databases.?
<!DOCTYPE html>
<html>
<body>
<h1>My first PHP page</h1>
<?php
use DateTime;
use DateTimeZone;
use InfluxDB\Options;
use InfluxDB\Client;
use InfluxDB\Adapter\GuzzleAdapter;
use GuzzleHttp\Client as GuzzleHttpClient;
use InfluxDB\Integration\Framework\TestCase as InfluxDBTestCase;
require 'composertest/vendor/autoload.php';
error_reporting(E_ALL);
ini_set('display_errors', 'on');
$http = new \GuzzleHttp\Client();
$options = new Options();
$options->setUsername("xyz");
$options->setPassword("1234");
$adapter = new GuzzleAdapter($http, $options);
$client = new Client($adapter);
//I need to select database "Test"
var_dump($client->query('select * from "app-search"'));
?>
</body>
</html>
Upvotes: 1
Views: 3729
Reputation: 1846
I think you asked this question in SO, on [email protected], and via email to [email protected]. The answer to the support@ ticket was (with thanks to Ross McDonald):
I believe what you are looking for is the
selectDB()
function. Here is a small sample that can be inserted towards the bottom of your example code:$database = $client->selectDB('Test'); var_dump($database->query('select * from "app-search"'));
Where queries are run using the
$database
variable, as opposed to the$client
variable.The InfluxDB PHP driver is actually developed and maintained by the InfluxDB community (and not by the InfluxDB organization itself), so more information about the driver (including code examples) can be found on the Github page here:
Upvotes: 2