Skip to content
This repository has been archived by the owner on Nov 15, 2022. It is now read-only.

[Feature request] Parameter Binding #140

Open
mehmetali opened this issue Oct 21, 2019 · 2 comments
Open

[Feature request] Parameter Binding #140

mehmetali opened this issue Oct 21, 2019 · 2 comments

Comments

@mehmetali
Copy link

InfluxDB supports binding parameters. This feature covers issue #53

@andres11362
Copy link

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

@lyrixx
Copy link

lyrixx commented Feb 18, 2022

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);

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants