1 | <?php |
||
12 | class MysqlConnectionAdapter |
||
13 | { |
||
14 | |||
15 | const DRIVER_TYPE_PDO = 'pdo'; |
||
16 | const DRIVER_TYPE_MYSQLI = 'mysqli'; |
||
17 | |||
18 | /** |
||
19 | * |
||
20 | * @var string |
||
21 | */ |
||
22 | protected $driver; |
||
23 | |||
24 | /** |
||
25 | * |
||
26 | * @var \mysqli|null |
||
27 | */ |
||
28 | protected $mysqli; |
||
29 | |||
30 | /** |
||
31 | * |
||
32 | * @var \PDO|null |
||
33 | */ |
||
34 | protected $pdo; |
||
35 | |||
36 | /** |
||
37 | * |
||
38 | * @throws Exception\InvalidArgumentException |
||
39 | * @param \mysqli|\PDO $conn |
||
40 | */ |
||
41 | 26 | public function __construct($conn) |
|
42 | { |
||
43 | 26 | if ($conn instanceof \mysqli) { |
|
44 | 4 | $this->mysqli = $conn; |
|
45 | 4 | $this->type = self::DRIVER_TYPE_MYSQLI; |
|
|
|||
46 | 26 | } elseif ($conn instanceof \PDO && $conn->getAttribute(\PDO::ATTR_DRIVER_NAME) == 'mysql') { |
|
47 | 25 | $this->pdo = $conn; |
|
48 | 25 | $this->type = self::DRIVER_TYPE_PDO; |
|
49 | 25 | } else { |
|
50 | $msg = "MysqlConnectionAdapter requires connection to be either 'pdo:mysql' or 'mysqli'"; |
||
51 | throw new Exception\InvalidArgumentException($msg); |
||
52 | } |
||
53 | 26 | } |
|
54 | |||
55 | /** |
||
56 | * Return current schema name |
||
57 | * @return string|false |
||
58 | */ |
||
59 | 26 | public function getCurrentSchema() |
|
68 | |||
69 | /** |
||
70 | * |
||
71 | * @param string $value |
||
72 | * @return string |
||
73 | */ |
||
74 | 6 | public function quoteValue($value) |
|
83 | |||
84 | /** |
||
85 | * Execute query and return query as an ArrayObject |
||
86 | * |
||
87 | * @param string $query |
||
88 | * @return ArrayObject |
||
89 | */ |
||
90 | 26 | public function query($query) |
|
99 | |||
100 | /** |
||
101 | * |
||
102 | * @param string $query |
||
103 | * @return ArrayObject |
||
104 | */ |
||
105 | 25 | protected function executePDO($query) |
|
125 | |||
126 | /** |
||
127 | * |
||
128 | * @param string $query |
||
129 | * @return ArrayObject |
||
130 | */ |
||
131 | 4 | protected function executeMysqli($query) |
|
155 | } |
||
156 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: