ClickHouse / PHP

Put ClickHouseinto your PHP day

Query builder, schema, migrations, and ORM in one package, with one API across six frameworks.

Hamster Xiao Cang, the clickhouse project pet

One client for schema, queries, and migrations

clickhouse-php connects to ClickHouse over HTTP, bringing query building, schema management, migrations, and ORM into a single package.

The same calls run in plain PHP, Laravel, Webman, ThinkPHP, Hyperf, Yii2, and Yii3, with no need to rewrite business code per framework.

  • Query builder and binding
  • Schema Builder and migrations
  • ORM and multiple connections
6Framework adapters
v2.3.1Current version
HTTPTransport
Hamster Xiao Cang Smile expression

Xiao Cang

A round yellow cartoon hamster wearing a PHP purple scarf and a yellow ClickHouse house tag, waving its right paw in greeting.

Queries, tables, migrations: leave them to me.

From one query to a full data layer

Build, create tables, migrate, and map, all in one namespace.

Query builder

Chain SELECT, INSERT, and aggregate queries, with parameter binding instead of string concatenation.

Schema builder

Describe table structure in PHP, with columns, indexes, and engines written in one place.

Migrations

Versioned migration files with run, rollback, and refresh.

ORM mapping

ActiveRecord models and read-only collections, keeping the flexibility of raw queries.

Pools and connections

Multiple connections with Swoole, Swow, and Workerman coroutine pools; FPM connects directly.

Six framework adapters

Laravel, Webman, ThinkPHP, Hyperf, Yii2, and Yii3 share the same core.

From a client to a complete data layer

Four releases that filled in queries, schema, migrations, and framework support.

v2.3.1

Streaming parse and release checks

Improves streaming response parsing and version release checks, and fills in documentation.

v2.3.0

Pet API integration

Moves pet forms into the Pet API, and they now appear in command output.

v2.1.0

Yii2 and Yii3 adapters

Adds the Yii2 application component and Yii3 DI integration, bringing framework support to six.

v2.0.0

Streaming reads and query SETTINGS

Fixes issues found in review and adds streaming reads plus query-level SETTINGS.

Changelog

Recent releases; the full list is on GitHub Releases.

Latest v2.3.1 All versions
v2.3.12026-10-19

Improves streaming parsing, release version checks, and documentation.

v2.3.02026-10-18

Pet forms are integrated into the Pet API and command output.

v2.2.02026-10-18

Adds a 1200x630 social preview image.

v2.1.32026-10-18

Redesigns the project pet as a cartoon hamster and removes HTML from the README.

v2.1.22026-10-18

Reserves commercial rights for the project visual assets.

v2.1.12026-09-29

Fixes Laravel 13 installation and Guzzle 8 compatibility.

Install and use

Install first, then run a minimal example.

PHP 8.0+ / HTTPFull README
Install
composer require erikwang2013/clickhouse-php
Minimal example
use Erikwang2013\ClickHouse\ClickHouse;

ClickHouse::bootstrap();

$rows = ClickHouse::table('logs')
    ->where('date', '>=', '2024-01-01')
    ->whereIn('level', ['error', 'warn'])
    ->orderBy('timestamp', 'desc')
    ->limit(100)
    ->get();

foreach ($rows as $row) {
    echo $row['message'];
}

Twelve Xiao Cang expressions

Hover for a moment and its mood changes.

Search this site

Try “upload”, “migration” or “JWT”.