Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Requires allow_url_fopen be set to true.
- //$query = 'CREATE TABLE table_01 (date Date, n UInt32) ENGINE = MergeTree() PARTITION BY toYYYYMM(date) ORDER BY (date, n)';
- //$query = 'SELECT * from table_01';
- $query = 'insert into table_01 values (1,2)';
- $ch_host = 'CH_HOST_IS_HERE';
- $CA_path = '/PATH/TO/CA.pem';
- $db = 'DATABASE_HERE';
- $user = 'USERNAME_HERE';
- $password = 'PASSWORD_HERE';
- $auth = [
- "X-ClickHouse-User: ${user}",
- "X-ClickHouse-Key: ${password}",
- 'Content-Length: 0',
- ];
- $ssl = [
- 'cafile' => $CA_path,
- 'verify_peer' => TRUE,
- ];
- $context = stream_context_create([
- 'http' => [
- 'method' => 'POST',
- 'protocol_version' => 1.1,
- 'header' => $auth,
- ],
- 'ssl' => $ssl
- ]);
- $url = sprintf(
- "https://${ch_host}:8443/?database=%s&query=%s",
- $db,
- urlencode($query)
- );
- $response = file_get_contents($url, FALSE, $context);
- print_r($response);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement