Connection   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 22
c 1
b 0
f 0
dl 0
loc 59
rs 10
wmc 9

4 Methods

Rating   Name   Duplication   Size   Complexity  
A open() 0 20 5
A warnings() 0 3 1
A quoteBinary() 0 3 1
A query() 0 8 2
1
<?php
2
3
namespace Lagdo\DbAdmin\Driver\PgSql\Db\Pdo;
4
5
use Lagdo\DbAdmin\Driver\Db\Pdo\Connection as PdoConnection;
6
7
/**
8
 * PostgreSQL driver to be used with the pdo_pgsql PHP extension.
9
 */
10
class Connection extends PdoConnection
11
{
12
    /**
13
     * @var int
14
     */
15
    public $timeout;
16
17
    /**
18
    * @inheritDoc
19
    */
20
    public function open(string $database, string $schema = '')
21
    {
22
        $server = str_replace(":", "' port='", addcslashes($this->driver->options('server'), "'\\"));
23
        $options = $this->driver->options();
24
        $username = $options['username'];
25
        $password = $options['password'];
26
        $database = ($database) ? addcslashes($database, "'\\") : "postgres";
27
        if (!$password) {
28
            $password = '';
29
        }
30
31
        //! client_encoding is supported since 9.1 but we can't yet use min_version here
32
        $this->dsn("pgsql:host='$server' client_encoding=utf8 dbname='$database'", $username, $password);
33
        if ($this->driver->minVersion(9, 0)) {
34
            $this->query("SET application_name = 'Jaxon DbAdmin'");
35
        }
36
        if (($schema)) {
37
            $this->query("SET search_path TO " . $this->driver->escapeId($schema));
38
        }
39
        return true;
40
    }
41
42
    /**
43
     * @inheritDoc
44
     */
45
    public function quoteBinary(string $string)
46
    {
47
        return $this->quote($string);
48
    }
49
50
    /**
51
     * @inheritDoc
52
     */
53
    public function query(string $query, bool $unbuffered = false)
54
    {
55
        $result = parent::query($query, $unbuffered);
56
        if ($this->timeout) {
57
            $this->timeout = 0;
58
            parent::query("RESET statement_timeout");
59
        }
60
        return $result;
61
    }
62
63
    /**
64
     * @inheritDoc
65
     */
66
    public function warnings()
67
    {
68
        return ''; // not implemented in PDO_PgSQL as of PHP 7.2.1
69
    }
70
}
71