一、安装扩展
composer require yandex/clickhouse-pdo二、配置env
DB_CONNECTION=clickhouse DB_HOST=your-clickhouse-host DB_PORT=8123 DB_DATABASE=your-clickhouse-database DB_USERNAME=your-clickhouse-username DB_PASSWORD=your-clickhouse-password
三、修改config/database.php
'connections' => [ // ... other connections ... 'clickhouse' => [ 'driver' => 'clickhouse', 'host' => env('DB_HOST', 'localhost'), 'port' => env('DB_PORT', 8123), 'database' => env('DB_DATABASE', 'forge'), 'username' => env('DB_USERNAME', 'forge'), 'password' => env('DB_PASSWORD', ''), 'options' => [ 'timeout' => 10, 'protocol' => 'https', // or 'http' ], ], ],
四、创建model
php artisan make:model ClickHouseModel
五、链接数据库
namespace App; use IlluminateDatabaseEloquentModel; class ClickHouseModel extends Model { protected $connection = 'clickhouse'; protected $table = 'clickhouse_table'; }