1: <?php
2: 3: 4: 5: 6:
7:
8:
9: namespace Rundiz\DataTable;
10:
11: 12: 13: 14: 15:
16: class Database
17: {
18:
19:
20: 21: 22:
23: public $PDO;
24:
25:
26: 27: 28: 29: 30:
31: public function __construct(array $config = [])
32: {
33: if (!array_key_exists('dsn', $config)) {
34: $config['dsn'] = '';
35: }
36: if (!array_key_exists('username', $config)) {
37: $config['username'] = '';
38: }
39: if (!array_key_exists('password', $config)) {
40: $config['password'] = '';
41: }
42: if (!array_key_exists('options', $config)) {
43: $config['options'] = [];
44: }
45:
46: try {
47: $this->PDO = new \PDO($config['dsn'], $config['username'], $config['password'], $config['options']);
48: $this->PDO->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_OBJ);
49: $this->PDO->setAttribute(\PDO::ATTR_EMULATE_PREPARES, true);
50: } catch (\PDOException $e) {
51: throw new \Exception($e->getMessage());
52: }
53: }
54:
55:
56: }
57: