PHP code example of lucasacoutinho / ext-clickhouse
1. Go to this page and download the library: Download lucasacoutinho/ext-clickhouse 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/ */
lucasacoutinho / ext-clickhouse example snippets
use ClickHouse\Driver\Client;
use ClickHouse\Driver\ClientOptions;
use ClickHouse\Driver\CompressionMethod;
$client = new Client(new ClientOptions(
'127.0.0.1',
9000,
'default',
'default',
'',
CompressionMethod::LZ4
));
$client->ping();
use ClickHouse\Driver\Block;
use ClickHouse\Driver\Column;
$client->execute(
'CREATE TABLE IF NOT EXISTS test '
. '(id UInt64, name String) ENGINE = Memory'
);
$block = new Block();
$block->appendColumn('id', Column::create('UInt64', [1, 2, 3]));
$block->appendColumn(
'name',
Column::create('String', ['Alice', 'Bob', 'Charlie'])
);
$client->insert('test', $block);
$rows = $client->select('SELECT * FROM test ORDER BY id');
$client->selectByBlock('SELECT * FROM test', function (Block $block): void {
foreach ($block->toArray() as $row) {
// Process one result block at a time.
}
});