1. Go to this page and download the library: Download smi2/phpclickhouse 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/ */
$statement = $db->select('SELECT * FROM my_table WHERE id = :id', ['id' => 42]);
$statement->rows(); // all rows
$statement->fetchOne(); // first row
$statement->count(); // row count
// Server-side typed binding — SQL injection impossible at protocol level
$result = $db->selectWithParams(
'SELECT * FROM users WHERE id = {id:UInt32} AND name = {name:String}',
['id' => 42, 'name' => 'Alice']
);
// Memory-efficient — one row at a time, no OOM
foreach ($db->selectGenerator('SELECT * FROM huge_table') as $row) {
processRow($row);
}
$db->write('CREATE TABLE IF NOT EXISTS my_table (id UInt32, name String) ENGINE = MergeTree ORDER BY id');
$db->write('DROP TABLE IF EXISTS my_table');
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.