PHP code example of crodas / influx-php

1. Go to this page and download the library: Download crodas/influx-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

crodas / influx-php example snippets


$client = new \crodas\InfluxPHP\Client(
   "localhost" /*default*/,
   8086 /* default */,
   "root" /* by default */,
   "root" /* by default */
);

$db = $client->createDatabase("foobar");
$client->createUser("foo", "bar"); // <-- create user/password

$client->createUser('username', "password");

$users = $client->getUsers();

$client->grantPrivilege(InfluxClient::PRIV_ALL, 'database', 'username');

// revoke rights by
$client->revokePrivilege(InfluxClient::PRIV_ALL, 'database', 'username');

$client->setAdmin('username');

// delete admin righty by:
$client->deleteAdmin('einuser');

$db = $client->foobar;

// single input:
$db->insert("some label", [ 'fields' => array('value' => 2)]); 

// single input; the 'name' identifier will be overwritten by array content:
$db->insert("some label", ['name'=> 'some label', 'fields' => array('value' => 2)]);

// multiple insert, this is better...
// The 'name' field is optional, if not set, the default parameter (here: 'foobar') will be used

$db->insert("foobar", array(
            array('name' => 'lala',   'fields' => array('type' => 'foobar', 'karma' => 25)),
            array(   'fields' => array('type' => 'foobar', 'karma' => 45)),
            ));



$db->insert("foobar",[['tags' => ['type' => 'one'], 'fields' => ['value' => 10]]]);


$db = $client->foobar;
// OR
$db = $client->getDatabase("foobar");

foreach ($db->query("SELECT * FROM foo") as $row) {
    var_dump($row, $row->time);
}


// Here the 'type' value is stored as metadata in the tags entry. So if there are two 'type' tags found, you will get two result series
$result = $db->query("SELECT count(value) FROM test1 where  time >= '2015-01-01T12:00:00Z' and time < '2015-01-02T00:00:00Z' group by time(1h), type");

json
{
    "rodas/influx-php": "^0.9"
    }
}
json
{
    "rodas/influx-php": "0.1.*"
    }
}