smi2/phpclickhouse
PHP client for ClickHouse with an easy, fluent API. Supports queries and inserts, result sets, bindings, and connection configuration for fast analytics workflows. Suitable for Laravel and standalone PHP apps needing reliable ClickHouse access.
Three ways to configure settings:
// 1. In config array
$config = [
'host' => 'x',
'port' => '8123',
'username' => 'x',
'password' => 'x',
'settings' => ['max_execution_time' => 100],
];
$db = new ClickHouseDB\Client($config);
// 2. Via constructor second argument
$db = new ClickHouseDB\Client($config, ['max_execution_time' => 100]);
// 3. Via set method
$db->settings()->set('max_execution_time', 100);
// 4. Bulk apply
$db->settings()->apply([
'max_execution_time' => 100,
'max_block_size' => 12345,
]);
// Check value
$db->settings()->getSetting('max_execution_time'); // 100
See example/exam10_settings.php.
$db->settings()->max_execution_time(200); // seconds
$db->settings()->https();
$config = [
'host' => 'cluster.clickhouse.dns.com',
'port' => '8123',
'sslCA' => '/path/to/ca.pem',
];
// In config
$config = [
'host' => 'host.com',
'port' => '8123',
'username' => 'default',
'password' => '',
'auth_method' => 1, // see constants below
];
| Constant | Value | Description |
|---|---|---|
AUTH_METHOD_HEADER |
1 | X-ClickHouse-User/Key headers (default) |
AUTH_METHOD_QUERY_STRING |
2 | URL parameters |
AUTH_METHOD_BASIC_AUTH |
3 | HTTP Basic Auth |
// Create new session
$db->useSession();
$session_id = $db->getSession();
$db->write('CREATE TEMPORARY TABLE IF NOT EXISTS temp_session_test (number UInt64)');
$db->write('INSERT INTO temp_session_test SELECT number * 1234 FROM system.numbers LIMIT 30');
// Reconnect with same session
$db->useSession($session_id);
$db->enableExtremes(true);
$db->enableHttpCompression(true);
How can I help you explore Laravel packages today?