1. Go to this page and download the library: Download hyvor/clickhouse-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/ */
hyvor / clickhouse-php example snippets
use Hyvor\Clickhouse\Clickhouse;
$clickhouse = new Clickhouse(
host: 'localhost',
port: 8123,
user: 'default',
password: '',
database: 'default',
);
$results = $clickhouse->select(
'SELECT * FROM users WHERE id < {id: UInt32}',
['id' => 10]
);
// get rows as arrays
$results->all(); // [[1, 'John'], [2, 'Jane']]
// get the first row
$results->first(); // [1, 'John']
// get the first column of the first row
// useful for aggregations like COUNT(*)
$results->value(); // 2
// loop through the rows
foreach ($results as $row) {
// $row is an array
}
// properties
$results->rows; // int (same as $results->count())
$results->rowsBeforeLimitAtLeast; // null | int
$results->elapsedTimeSeconds; // float
$results->rowsRead; // int
$results->bytesRead; // int
$clickhouse->query('DROP TABLE users');
// with params
$clickhouse->query('QUERY', ['param' => 1]);
$clickhouse = new Clickhouse();
// example:
// by default, Clickhouse update mutations are async
// here, we set mutations to sync
$clickhouse->query('SET mutations_sync = 1');
// all queries in this session (using the same $clickhouse object) will be sync
$clickhouse->query(
'ALTER TABLE users UPDATE name = {name: String} WHERE id = 1',
['name' => 'John']
);
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.