Conditions | 3 |
Paths | 4 |
Total Lines | 28 |
Code Lines | 16 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 12 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
24 | protected function connectToServer(): PDO |
||
25 | { |
||
26 | ini_set('mysql.connect_timeout', strval($this->config->getTimeout())); |
||
27 | ini_set('default_socket_timeout', strval($this->config->getTimeout())); |
||
28 | |||
29 | $connection = new PDO( |
||
30 | sprintf('mysql:host=%s;port=%d;dbname=%s', |
||
31 | $this->config->getLocation(), |
||
32 | $this->config->getPort(), |
||
33 | $this->config->getDatabase() |
||
34 | ), |
||
35 | $this->config->getUser(), |
||
36 | $this->config->getPassword() |
||
37 | ); |
||
38 | |||
39 | $connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
||
40 | |||
41 | if ($this->config->isPersistent()) { |
||
42 | $connection->setAttribute(PDO::ATTR_PERSISTENT, true); |
||
43 | } |
||
44 | |||
45 | foreach ($this->attributes as $key => $value){ |
||
46 | $connection->setAttribute($key, $value); |
||
47 | } |
||
48 | |||
49 | $connection->query('SET NAMES utf8;'); |
||
50 | |||
51 | return $connection; |
||
52 | } |
||
54 |