public function __construct(array $params, $username, $password, array $driverOptions = array()) { // directly get the database object $dsn = 'influxdb://'; if ($username) { $dsn .= sprintf("%s:%s@", $username, $password); } if ($params["host"]) { $dsn .= $params["host"]; } else { $dsn .= 'localhost'; } if ($params["port"]) { $dsn .= ':' . $params["port"]; } else { $dsn .= ':8086'; } if ($params["dbname"]) { $dsn .= '/' . $params["dbname"]; } else { $dsn .= '/'; } $this->database = Client::fromDSN($dsn); $this->client = $this->database->getClient(); }
public function getConnect() { if (!$this->connection) { $this->connection = Client::fromDSN(sprintf('influxdb://%s:%s@%s:%s/%s', $this->user, $this->password, $this->host, $this->port, $this->db)); } return $this->connection; }
public function testFactoryMethod() { $client = $this->getClient('test', 'test', true); $staticClient = \InfluxDB\Client::fromDSN('https+influxdb://test:test@localhost:8086/'); $this->assertEquals($client, $staticClient); $db = $client->selectDB('testdb'); $staticDB = \InfluxDB\Client::fromDSN('https+influxdb://test:test@localhost:8086/testdb'); $this->assertEquals($db, $staticDB); }
function influxdb_connect() { global $config; $influxdb_cred = ''; if (!empty($config['influxdb']['username']) && !empty($config['influxdb']['password'])) { $influxdb_cred = $config['influxdb']['username'] . ':' . $config['influxdb']['password'] . '@'; d_echo('Using authentication for InfluxDB'); } $influxdb_url = $influxdb_cred . $config['influxdb']['host'] . ':' . $config['influxdb']['port'] . '/' . $config['influxdb']['db']; d_echo($config['influxdb']['transport'] . " transport being used"); if ($config['influxdb']['transport'] == 'http') { $influxdb_conn = 'influxdb'; } elseif ($config['influxdb']['transport'] == 'udp') { $influxdb_conn = 'udp+influxdb'; } else { echo 'InfluxDB support enabled but no valid transport details provided'; return false; } $db = \InfluxDB\Client::fromDSN($influxdb_conn . '://' . $influxdb_url); return $db; }