Completed
Push — master ( 8040a7...b5bbbe )
by Igor
22:35 queued 13:29
created

CustomDegeneration::bindParams()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 1
nc 1
nop 1
1
<?php
2
3
4
include_once __DIR__ . '/../include.php';
5
include_once __DIR__ . '/Helper.php';
6
\ClickHouseDB\Example\Helper::init();
7
8
9
class CustomDegeneration implements \ClickHouseDB\Query\Degeneration
10
{
11
    private $bindings=[];
12
    public function bindParams(array $bindings)
13
    {
14
        $this->bindings=$bindings;
15
    }
16
    public function process($sql)
17
    {
18
        if (sizeof($this->bindings))
19
        {
20
            foreach ($this->bindings as $key=>$value)
21
            {
22
                $sql=str_ireplace('%'.$key.'%',$value,$sql);
23
            }
24
        }
25
        return str_ireplace('XXXX','SELECT',$sql);
26
    }
27
}
28
29
30
$config = include_once __DIR__ . '/00_config_connect.php';
31
32
33
$db = new ClickHouseDB\Client($config);
34
35
print_r($db->select('SELECT 1 as ping')->fetchOne());
36
37
38
39
// CustomConditions
40
$db->addQueryDegeneration(new CustomDegeneration());
41
42
43
// strreplace XXXX=>SELECT
44
print_r($db->select('XXXX 1 as ping')->fetchOne());
45
46
47
48
// SELECT 1 as ping
49
print_r($db->select('XXXX 1 as %ZX%',['ZX'=>'ping'])->fetchOne());
50