github地址:https://github.com/smi2/phpClickHouse/tree/e27b04d482e9922df8bf1ea0880bf2985d2e06d0
ORM搭建学习:https://www.cnblogs.com/glory-jzx/p/4470129.html
1.下载适合自己php版本的 clickhouse (我司php 5.6 所以最高只能用1.1.2)
包管理地址:https://packagist.org/packages/smi2/phpclickhouse#1.1.2
github地址:https://github.com/smi2/phpClickHouse/tree/e27b04d482e9922df8bf1ea0880bf2985d2e06d0
2.解压出来后:
解压出来将包含 example、src、tests、include.php.....等所有文件、文件夹
放到自己指定工程目录:D:projectTest hird_partyphpclickhouse1.1.2
<?php
include_once __DIR__ . '/third_party/phpclickhouse1.1.2/include.php';
$config = [
'host' => '10.222.1.213',
'port' => '8123',
'username' => 'default',
'password' => ''
];
$db = new ClickHouseDBClient($config);
$db->database('default');
$db->setTimeout(1.5); // 1500 ms
$db->setTimeout(10); // 10 seconds
$db->setConnectTimeOut(5); // 5 seconds
$db->ping();
?>
使用默认配置去连接 clickhouse
错误:Fatal error: Call to undefined function curl_init()
解决:在php.ini 文件中 将 extension=php_curl.dll 前的分号去掉
错误:Warning: PHP Startup: Unable to load dynamic library 'C:phpextphp_curl.dll
因为刚才php.ini文件引入的 php_curl.dll 文件系统默认在 ‘C:/php/ext/’下去找
两种解决方式,把该文件拷贝过去,或者php.ini中配置查找路径:
; extension_dir = "./"
; On windows:
extension_dir = "ext" #将此行前面分号去掉
1 <?php 2 include_once __DIR__ . '/third_party/phpclickhouse1.1.2/include.php'; 3 4 $config = [ 5 'host' => '10.222.1.213', 6 'port' => '8123', 7 'username' => 'sangfor', 8 'password' => 'sangfor123' 9 ]; 10 $db = new ClickHouseDBClient($config); 11 $db->database('test'); 12 $db->setTimeout(1.5); // 1500 ms 13 $db->setTimeout(10); // 10 seconds 14 $db->setConnectTimeOut(5); // 5 seconds 15 16 $db->ping(); 17 //print_r($db->showDatabases()); 18 //$data = $db->https() 19 $data_state = $db->select("select * from test.netflow where record_time>'2020-04-30 23:59:59'"); 20 $cur_info_all = $data_state->rawData(); 21 $cur_data = $cur_info_all["data"]; 22 echo(json_encode($cur_data)); 23 //$cur_data = serialize($data_state->rawData()); 24 //print_r($data_state); 25 26 ?>