| Conditions | 2 |
| Paths | 2 |
| Total Lines | 28 |
| Code Lines | 19 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 24 | public function __construct($query, array $options) |
||
| 25 | { |
||
| 26 | $resolver = new OptionsResolver(); |
||
| 27 | $resolver->setDefaults([ |
||
| 28 | 'host' => 'localhost', |
||
| 29 | 'port' => 3306, |
||
| 30 | 'username' => null, |
||
| 31 | 'password' => null, |
||
| 32 | 'database_name' => null, |
||
| 33 | 'query' => $query, |
||
| 34 | 'driver_options' => [ |
||
| 35 | PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, |
||
| 36 | ], |
||
| 37 | ]); |
||
| 38 | |||
| 39 | $this->options = $resolver->resolve($options); |
||
| 40 | |||
| 41 | /** @noinspection SpellCheckingInspection */ |
||
| 42 | $dbh = $pdo = new PDO( |
||
|
|
|||
| 43 | sprintf('mysql:host=%s;dbname=%s', $this->options['host'], $this->options['database_name']), |
||
| 44 | $this->options['username'], |
||
| 45 | $this->options['password'], |
||
| 46 | $this->options['driver_options'] |
||
| 47 | ); |
||
| 48 | foreach ($dbh->query($query) as $row) { |
||
| 49 | $this->addItem($row); |
||
| 50 | } |
||
| 51 | $dbh = null; |
||
| 52 | } |
||
| 54 |