Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Phpclickhouse Laravel Package

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.

View on GitHub
Deep Wiki
Context7

layout: default title: Structured Exceptions

< Back to Home

Structured Exceptions

The library provides detailed exception information from ClickHouse errors.

Exception Hierarchy

ClickHouseException (interface)
├── QueryException (LogicException)
│   └── DatabaseException (ClickHouse server errors)
├── TransportException (RuntimeException) — curl/HTTP errors
└── ClickHouseUnavailableException — connection refused

DatabaseException

Thrown when ClickHouse returns a server error (bad SQL, missing table, auth failure, etc.).

use ClickHouseDB\Exception\DatabaseException;

try {
    $db->select('SELECT * FROM non_existent_table');
} catch (DatabaseException $e) {
    echo $e->getMessage();                  // "Table default.non_existent_table doesn't exist.\nIN:SELECT ..."
    echo $e->getCode();                     // 60
    echo $e->getClickHouseExceptionName();  // 'UNKNOWN_TABLE' (CH 22+) or null (older versions)
    echo $e->getQueryId();                  // 'abc-123-def' (from X-ClickHouse-Query-Id header)
}

Available Methods

Method Returns Description
getMessage() string Error message + SQL
getCode() int ClickHouse error code
getClickHouseExceptionName() ?string e.g. UNKNOWN_TABLE, SYNTAX_ERROR (CH 22+)
getQueryId() ?string Query ID from response header
getRequestDetails() array Request metadata
getResponseDetails() array Response metadata

Common Error Codes

Code Exception Name Description
60 UNKNOWN_TABLE Table doesn't exist
62 SYNTAX_ERROR SQL syntax error
81 DATABASE_NOT_FOUND Database doesn't exist
115 UNKNOWN_SETTING Invalid setting
192 UNKNOWN_USER User doesn't exist
241 MEMORY_LIMIT_EXCEEDED Query exceeded memory limit
516 AUTHENTICATION_FAILED Wrong password or user

Error Format Support

The library parses both old and new ClickHouse error formats:

# Old format (CH < 22)
Code: 60. DB::Exception: Table default.xxx doesn't exist., e.what() = DB::Exception

# New format (CH 22+)
Code: 60. DB::Exception: Table default.xxx doesn't exist. (UNKNOWN_TABLE) (version 24.3.2.23 (official build))

TransportException

Thrown for HTTP/curl-level errors (timeouts, connection refused, etc.).

use ClickHouseDB\Exception\TransportException;

try {
    $db->select('SELECT sleep(100)');
} catch (TransportException $e) {
    echo $e->getMessage(); // "Operation timed out"
    echo $e->getCode();    // curl error number
}

ClickHouseUnavailableException

Thrown when the server is unreachable.

use ClickHouseDB\Exception\ClickHouseUnavailableException;

try {
    $db->ping(true);
} catch (ClickHouseUnavailableException $e) {
    echo "ClickHouse is down: " . $e->getMessage();
}
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor