
1、安装influxdb-php
在项目中打开cmder,执行如下命令,电脑必须安装了composer
composer require influxdb/influxdb-php2、简单的操作
创建链接对象
方式一
$client = new InfluxDB\Client($host, $port);方式二
$database = InfluxDB\Client::fromDSN(sprintf('influxdb://user:pass@%s:%s/%s', $host, $port, $dbname));
$client = $database->getClient();设置查询数据库
$database = $client->selectDB('testdb');执行查询语句
$result = $database->query('select * from test LIMIT 5');将结果集转成一个数组
$points = $result->getPoints();可以使用getQueryBuilder简化查询
$result = $database->getQueryBuilder()
->select('cpucount')
->from('test')
->limit(2)
->offset(2)
->getResultSet()
->getPoints();
$query = $database->getQueryBuilder()
->select('cpucount')
->from('test')
->where(["region = 'us-west'"])
->getQuery();添加数据
$points = array(
new Point(
'test', // 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', // name of the measurement
0.84, // the measurement value
['host' => 'server01', 'region' => 'us-west'], // optional tags
['cpucount' => 10], // optional additional fields
1435255849 // Time precision has to be set to seconds!
)
);
$result = $database->writePoints($points, Database::PRECISION_SECONDS);3、封装成类使用
详细的到一下地址查看
评论
暂无评论
评论(0)