PHP code example of ksaazaks / phpclickhouse-laravel
1. Go to this page and download the library: Download ksaazaks/phpclickhouse-laravel library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?phprequire_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
namespaceApp\Models\Clickhouse;
usePhpClickHouseLaravel\BaseModel;
classMyTableextendsBaseModel{
// Not necessary. Can be obtained from class name MyTable => my_tableprotected $table = 'my_table';
protected $connection = 'my_connection';
}
classCreateMyTableextends \PhpClickHouseLaravel\Migration{
/**
* Run the migrations.
*
* @return void
*/publicfunctionup(){
static::write('
CREATE TABLE my_table (
id UInt32,
created_at DateTime,
field_one String,
field_two Int32
)
ENGINE = MergeTree()
ORDER BY (id)
');
}
/**
* Reverse the migrations.
*
* @return void
*/publicfunctiondown(){
static::write('DROP TABLE my_table');
}
}
// Split the result into chunks of 30 rows
$rows = MyTable::select(['field_one', 'field_two'])
->chunk(30, function($rows){
foreach ($rows as $row) {
echo $row['field_two'] . "\n";
}
});
namespaceApp\Models\Clickhouse;
usePhpClickHouseLaravel\BaseModel;
classMyTableextendsBaseModel{
// Not necessary. Can be obtained from class name MyTable => my_tableprotected $table = 'my_table';
// All inserts will be in the table $tableForInserts // But all selects will be from $tableprotected $tableForInserts = 'my_table_buffer';
}
namespaceApp\Models\Clickhouse;
usePhpClickHouseLaravel\BaseModel;
classMyTableextendsBaseModel{
// All SELECT's and INSERT's on $tableprotected $table = 'my_table_buffer';
// OPTIMIZE and DELETE on $tableSourcesprotected $tableSources = 'my_table';
}
// Array data type
MyTable::insertAssoc([[1,'str',new InsertArray(['a','b'])]]);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.