1. Go to this page and download the library: Download bavix/clickhouse-php-client 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/ */
bavix / clickhouse-php-client example snippets
$server = new Tinderbox\Clickhouse\Server('127.0.0.1', '8123', 'default', 'user', 'pass');
$serverProvider = (new Tinderbox\Clickhouse\ServerProvider())->addServer($server);
$client = new Tinderbox\Clickhouse\Client($serverProvider);
$result = $client->readOne('select number from system.numbers limit 100');
foreach ($result as $number) {
echo $number['number'].PHP_EOL;
}
['UInt64']
$result = $client->readOne('select number from system.numbers where number in _numbers limit 100', new TempTable('_numbers', 'numbers.csv', [
'number' => 'UInt64'
]));
foreach ($result as $number) {
echo $number['number'].PHP_EOL;
}
list($clicks, $visits, $views) = $client->read([
['query' => "select * from clicks where date = '2017-01-01'"],
['query' => "select * from visits where date = '2017-01-01'"],
['query' => "select * from views where date = '2017-01-01'"],
]);
foreach ($clicks as $click) {
echo $click['date'].PHP_EOL;
}
list($clicks, $visits, $views) = $client->read([
['query' => "select * from clicks where date = '2017-01-01' and userId in _users", new TempTable('_users', 'users.csv', ['number' => 'UInt64'])],
['query' => "select * from visits where date = '2017-01-01'"],
['query' => "select * from views where date = '2017-01-01'"],
]);
foreach ($clicks as $click) {
echo $click['date'].PHP_EOL;
}
$client->writeOne("insert into table (date, column) values ('2017-01-01',1), ('2017-01-02',2)");
$client->write([
['query' => "insert into table (date, column) values ('2017-01-01',1), ('2017-01-02',2)"],
['query' => "insert into table (date, column) values ('2017-01-01',1), ('2017-01-02',2)"],
['query' => "insert into table (date, column) values ('2017-01-01',1), ('2017-01-02',2)"]
]);
$client->writeFiles('table', ['date', 'column'], [
new Tinderbox\Clickhouse\Common\File('/file-1.csv'),
new Tinderbox\Clickhouse\Common\File('/file-2.csv')
]);
$client->insertFiles('table', ['date', 'column'], [
new Tinderbox\Clickhouse\Common\File('/file-1.tsv'),
new Tinderbox\Clickhouse\Common\File('/file-2.tsv')
], Tinderbox\Clickhouse\Common\Format::TSV);
$client->writeOne('DROP TABLE table');
bash
composer
file-1.tsv
file-2.tsv
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.