influxdata/influxdb-php

[Feature request] Parameter Binding

Opened this issue · 2 comments

InfluxDB supports binding parameters. This feature covers issue #53

Hi, could you please give me an example of how to use the binding parameters in the library? I'm not sure how to do it.

Sorry for my bad English.

Thanks in advance

Here is an example:

require __DIR__ . '/vendor/autoload.php';

use InfluxDB\Database;
use InfluxDB\Point;

$client = new InfluxDB\Client('127.0.0.1');

$database = $client->selectDB('stat');

$points = array(
    new Point(
        'test_metric', // name of the measurement
        0.64, // the measurement value
        ['host' => 'server01', 'region' => 'us-west'], // optional tags
        ['cpucount' => 10], // optional additional fields
        1435255849 // Time precision has to be set to seconds!
    ),
    new Point(
        'test_metric', // name of the measurement
        0.84, // the measurement value
        ['host' => 'server02', 'region' => 'us-west'], // optional tags
        ['cpucount' => 10], // optional additional fields
        1435255849 // Time precision has to be set to seconds!
    )
);

// we are writing unix timestamps, which have a second precision
$result = $database->writePoints($points, Database::PRECISION_SECONDS);

$result = $database->query(
    // 'select * from test_metric where host = $host LIMIT 5',
    'select * from test_metric where "host" = $host LIMIT 5',
    [
            'params' => json_encode([
                'host' => 'server02'
            ]),
    ],
)->getPoints();

dd($result);