@@ -168,7 +168,7 @@ |
||
168 | 168 | * @param string $sql The SQL statement to prepare |
169 | 169 | * @param array $values a multidimensional array with the values, each row represents one line to insert. |
170 | 170 | * |
171 | - * @return bool true query success, otherwise false |
|
171 | + * @return boolean|null true query success, otherwise false |
|
172 | 172 | */ |
173 | 173 | public function multi($sql, array $values){ |
174 | 174 | // TODO: Implement multi() method. |
@@ -1,14 +1,14 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Class SQLite3Driver |
|
4 | - * |
|
5 | - * @filesource SQLite3Driver.php |
|
6 | - * @created 21.02.2016 |
|
7 | - * @package chillerlan\Database\Drivers\SQLite |
|
8 | - * @author Smiley <[email protected]> |
|
9 | - * @copyright 2016 Smiley |
|
10 | - * @license MIT |
|
11 | - */ |
|
3 | + * Class SQLite3Driver |
|
4 | + * |
|
5 | + * @filesource SQLite3Driver.php |
|
6 | + * @created 21.02.2016 |
|
7 | + * @package chillerlan\Database\Drivers\SQLite |
|
8 | + * @author Smiley <[email protected]> |
|
9 | + * @copyright 2016 Smiley |
|
10 | + * @license MIT |
|
11 | + */ |
|
12 | 12 | |
13 | 13 | namespace chillerlan\Database\Drivers\SQLite; |
14 | 14 |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | /** |
22 | 22 | * |
23 | 23 | */ |
24 | -class SQLite3Driver extends DBBaseDriver implements DBDriverInterface{ |
|
24 | +class SQLite3Driver extends DBBaseDriver implements DBDriverInterface { |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * Holds the database resource object |
@@ -36,20 +36,20 @@ discard block |
||
36 | 36 | * @return \SQLite3 the database resource object |
37 | 37 | * @throws \chillerlan\Database\DBException |
38 | 38 | */ |
39 | - public function connect(){ |
|
39 | + public function connect() { |
|
40 | 40 | |
41 | - if($this->db instanceof SQLite3){ |
|
41 | + if ($this->db instanceof SQLite3) { |
|
42 | 42 | return $this->db; |
43 | 43 | } |
44 | 44 | |
45 | - try{ |
|
45 | + try { |
|
46 | 46 | $this->db = new SQLite3( |
47 | 47 | $this->options->database, |
48 | 48 | $this->options->sqlite_flags, |
49 | 49 | $this->options->sqlite_encryption_key |
50 | 50 | ); |
51 | 51 | } |
52 | - catch(Exception $Exception){ |
|
52 | + catch (Exception $Exception) { |
|
53 | 53 | throw new DBException($Exception->getMessage()); |
54 | 54 | } |
55 | 55 | |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | * |
62 | 62 | * @return $this |
63 | 63 | */ |
64 | - public function disconnect(){ |
|
64 | + public function disconnect() { |
|
65 | 65 | $this->db->close(); |
66 | 66 | } |
67 | 67 | |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | * |
71 | 71 | * @return string php's database client string |
72 | 72 | */ |
73 | - public function getClientInfo(){ |
|
73 | + public function getClientInfo() { |
|
74 | 74 | return 'SQLite '.SQLite3::version()['versionString']; |
75 | 75 | } |
76 | 76 | |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | * |
80 | 80 | * @return string database's serverinfo string |
81 | 81 | */ |
82 | - public function getServerInfo(){ |
|
82 | + public function getServerInfo() { |
|
83 | 83 | return 'N/A (SQLite '.SQLite3::version()['versionString'].')'; |
84 | 84 | } |
85 | 85 | |
@@ -93,25 +93,25 @@ discard block |
||
93 | 93 | * |
94 | 94 | * @return array|string array or string. escaped. obviously. |
95 | 95 | */ |
96 | - public function escape($data, $specialchars = false){ |
|
96 | + public function escape($data, $specialchars = false) { |
|
97 | 97 | |
98 | - if(is_array($data)){ |
|
98 | + if (is_array($data)) { |
|
99 | 99 | |
100 | - foreach($data as $key => $value){ |
|
100 | + foreach ($data as $key => $value) { |
|
101 | 101 | $data[$key] = $this->escape($value, $specialchars); |
102 | 102 | } |
103 | 103 | |
104 | 104 | } |
105 | - else if(is_object($data)){ |
|
105 | + else if (is_object($data)) { |
|
106 | 106 | |
107 | - foreach($data as $key => $value){ |
|
107 | + foreach ($data as $key => $value) { |
|
108 | 108 | $data->{$key} = $this->escape($value, $specialchars); |
109 | 109 | } |
110 | 110 | |
111 | 111 | } |
112 | - else{ |
|
112 | + else { |
|
113 | 113 | |
114 | - if($specialchars){ |
|
114 | + if ($specialchars) { |
|
115 | 115 | $data = htmlspecialchars($data, ENT_HTML5, 'UTF-8', false); |
116 | 116 | } |
117 | 117 | |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | * @return array|bool array with results, true on void query success, otherwise false. |
139 | 139 | * @throws \mysqli_sql_exception |
140 | 140 | */ |
141 | - public function raw($sql, $index = '', $assoc = true, $fetch_array = false){ |
|
141 | + public function raw($sql, $index = '', $assoc = true, $fetch_array = false) { |
|
142 | 142 | // TODO: Implement raw() method. |
143 | 143 | } |
144 | 144 | |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | * |
157 | 157 | * @return array|bool Array with results, true on void query success, otherwise false |
158 | 158 | */ |
159 | - public function prepared($sql, array $values = [], $index = '', $assoc = true, $fetch_array = false){ |
|
159 | + public function prepared($sql, array $values = [], $index = '', $assoc = true, $fetch_array = false) { |
|
160 | 160 | // TODO: Implement prepared() method. |
161 | 161 | } |
162 | 162 | |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | * |
171 | 171 | * @return bool true query success, otherwise false |
172 | 172 | */ |
173 | - public function multi($sql, array $values){ |
|
173 | + public function multi($sql, array $values) { |
|
174 | 174 | // TODO: Implement multi() method. |
175 | 175 | } |
176 | 176 | } |
@@ -48,8 +48,7 @@ discard block |
||
48 | 48 | $this->options->sqlite_flags, |
49 | 49 | $this->options->sqlite_encryption_key |
50 | 50 | ); |
51 | - } |
|
52 | - catch(Exception $Exception){ |
|
51 | + } catch(Exception $Exception){ |
|
53 | 52 | throw new DBException($Exception->getMessage()); |
54 | 53 | } |
55 | 54 | |
@@ -101,15 +100,13 @@ discard block |
||
101 | 100 | $data[$key] = $this->escape($value, $specialchars); |
102 | 101 | } |
103 | 102 | |
104 | - } |
|
105 | - else if(is_object($data)){ |
|
103 | + } else if(is_object($data)){ |
|
106 | 104 | |
107 | 105 | foreach($data as $key => $value){ |
108 | 106 | $data->{$key} = $this->escape($value, $specialchars); |
109 | 107 | } |
110 | 108 | |
111 | - } |
|
112 | - else{ |
|
109 | + } else{ |
|
113 | 110 | |
114 | 111 | if($specialchars){ |
115 | 112 | $data = htmlspecialchars($data, ENT_HTML5, 'UTF-8', false); |
@@ -23,13 +23,13 @@ discard block |
||
23 | 23 | /** |
24 | 24 | * Class MyClass |
25 | 25 | */ |
26 | -class MyClass{ |
|
26 | +class MyClass { |
|
27 | 27 | use DatabaseTrait; |
28 | 28 | |
29 | 29 | protected $DBDriverInterface; |
30 | 30 | protected $options; |
31 | 31 | |
32 | - public function __construct(stdClass $class_options){ |
|
32 | + public function __construct(stdClass $class_options) { |
|
33 | 33 | $this->options = $class_options; |
34 | 34 | |
35 | 35 | $this->DBDriverInterface = $this->dbconnect($this->options->dbdriver, $this->options->dbconfig); |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | var_dump($this->db); |
43 | 43 | } |
44 | 44 | |
45 | - public function __destruct(){ |
|
45 | + public function __destruct() { |
|
46 | 46 | $this->DBDriverInterface->disconnect(); |
47 | 47 | } |
48 | 48 |
@@ -17,6 +17,6 @@ |
||
17 | 17 | /** |
18 | 18 | * Placeholder |
19 | 19 | */ |
20 | -class DBException extends Exception{ |
|
20 | +class DBException extends Exception { |
|
21 | 21 | |
22 | 22 | } |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | /** |
16 | 16 | * |
17 | 17 | */ |
18 | -class DBOptions{ |
|
18 | +class DBOptions { |
|
19 | 19 | |
20 | 20 | /** |
21 | 21 | * The host |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | * |
130 | 130 | * @var int |
131 | 131 | */ |
132 | - public $sqlite_flags = SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE; |
|
132 | + public $sqlite_flags = SQLITE3_OPEN_READWRITE|SQLITE3_OPEN_CREATE; |
|
133 | 133 | /** |
134 | 134 | * An optional encryption key used when encrypting and decrypting an SQLite database. |
135 | 135 | * |
@@ -144,11 +144,11 @@ discard block |
||
144 | 144 | * |
145 | 145 | * @param array $params |
146 | 146 | */ |
147 | - public function __construct(array $params = []){ |
|
147 | + public function __construct(array $params = []) { |
|
148 | 148 | |
149 | - if(is_array($params) && !empty($params)){ |
|
149 | + if (is_array($params) && !empty($params)) { |
|
150 | 150 | |
151 | - foreach($params as $key => $value){ |
|
151 | + foreach ($params as $key => $value) { |
|
152 | 152 | $this->{$key} = $value; |
153 | 153 | } |
154 | 154 |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | * |
21 | 21 | * @see http://blog.mclaughlinsoftware.com/2010/02/21/php-binding-a-wildcard/ LIKE %...% -> LIKE CONCAT('%',?,'%') |
22 | 22 | */ |
23 | -class DBBaseDriver{ |
|
23 | +class DBBaseDriver { |
|
24 | 24 | |
25 | 25 | /** |
26 | 26 | * Holds the database resource object |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | * |
57 | 57 | * @param \chillerlan\Database\DBOptions $options |
58 | 58 | */ |
59 | - public function __construct(DBOptions $options){ |
|
59 | + public function __construct(DBOptions $options) { |
|
60 | 60 | $this->options = $options; |
61 | 61 | } |
62 | 62 | |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | * |
66 | 66 | * @return resource the database resource object |
67 | 67 | */ |
68 | - public function getDBResource(){ |
|
68 | + public function getDBResource() { |
|
69 | 69 | return $this->db; |
70 | 70 | } |
71 | 71 | |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | * |
75 | 75 | * @return array stats |
76 | 76 | */ |
77 | - public function getStats(){ |
|
77 | + public function getStats() { |
|
78 | 78 | return $this->stats; |
79 | 79 | } |
80 | 80 | |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | * |
84 | 84 | * @return $this |
85 | 85 | */ |
86 | - public function enableStats(){ |
|
86 | + public function enableStats() { |
|
87 | 87 | $this->stats_enabled = true; |
88 | 88 | |
89 | 89 | return $this; |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | * |
95 | 95 | * @return $this |
96 | 96 | */ |
97 | - public function disableStats(){ |
|
97 | + public function disableStats() { |
|
98 | 98 | $this->stats_enabled = false; |
99 | 99 | |
100 | 100 | return $this; |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | * |
106 | 106 | * @return $this |
107 | 107 | */ |
108 | - public function clearStats(){ |
|
108 | + public function clearStats() { |
|
109 | 109 | $this->stats = []; |
110 | 110 | |
111 | 111 | return $this; |
@@ -116,12 +116,12 @@ discard block |
||
116 | 116 | * |
117 | 117 | * @param array $stats |
118 | 118 | */ |
119 | - public function addStats(array $stats){ |
|
120 | - if($this->stats_enabled){ |
|
119 | + public function addStats(array $stats) { |
|
120 | + if ($this->stats_enabled) { |
|
121 | 121 | $stat = new Querystats; |
122 | 122 | |
123 | - foreach($stat as $key => $value){ |
|
124 | - if(isset($stats[$key])){ |
|
123 | + foreach ($stat as $key => $value) { |
|
124 | + if (isset($stats[$key])) { |
|
125 | 125 | $stat->{$key} = $stats[$key]; |
126 | 126 | } |
127 | 127 | } |
@@ -15,7 +15,7 @@ |
||
15 | 15 | /** |
16 | 16 | * |
17 | 17 | */ |
18 | -interface DBDriverInterface{ |
|
18 | +interface DBDriverInterface { |
|
19 | 19 | |
20 | 20 | /** |
21 | 21 | * Establishes a database connection and returns the connection object |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | /** |
24 | 24 | * |
25 | 25 | */ |
26 | -class MySQLiDriver extends DBBaseDriver implements DBDriverInterface{ |
|
26 | +class MySQLiDriver extends DBBaseDriver implements DBDriverInterface { |
|
27 | 27 | |
28 | 28 | /** |
29 | 29 | * Holds the database resource object |
@@ -38,19 +38,19 @@ discard block |
||
38 | 38 | * @return mysqli the database resource object |
39 | 39 | * @throws DBException |
40 | 40 | */ |
41 | - public function connect(){ |
|
41 | + public function connect() { |
|
42 | 42 | |
43 | - if($this->db instanceof mysqli){ |
|
43 | + if ($this->db instanceof mysqli) { |
|
44 | 44 | return $this->db; |
45 | 45 | } |
46 | 46 | |
47 | 47 | $this->db = mysqli_init(); |
48 | 48 | |
49 | - if(!$this->db->options(MYSQLI_OPT_CONNECT_TIMEOUT, $this->options->mysqli_timeout)){ |
|
49 | + if (!$this->db->options(MYSQLI_OPT_CONNECT_TIMEOUT, $this->options->mysqli_timeout)) { |
|
50 | 50 | throw new DBException('Could not set database timeout.'); |
51 | 51 | } |
52 | 52 | |
53 | - if($this->options->use_ssl){ |
|
53 | + if ($this->options->use_ssl) { |
|
54 | 54 | $this->db->ssl_set( |
55 | 55 | $this->options->ssl_key, |
56 | 56 | $this->options->ssl_cert, |
@@ -60,21 +60,21 @@ discard block |
||
60 | 60 | ); |
61 | 61 | } |
62 | 62 | |
63 | - if(!$this->db->real_connect( |
|
63 | + if (!$this->db->real_connect( |
|
64 | 64 | $this->options->host, |
65 | 65 | $this->options->username, |
66 | 66 | $this->options->password, |
67 | 67 | $this->options->database, |
68 | 68 | (int)$this->options->port, |
69 | 69 | $this->options->socket |
70 | - )){ |
|
70 | + )) { |
|
71 | 71 | throw new DBException('Could not connect to the database.'); |
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
75 | 75 | * @see https://mathiasbynens.be/notes/mysql-utf8mb4 How to support full Unicode in MySQL |
76 | 76 | */ |
77 | - if(!$this->db->set_charset($this->options->mysql_charset)){ |
|
77 | + if (!$this->db->set_charset($this->options->mysql_charset)) { |
|
78 | 78 | throw new DBException('Could not set database character set.'); |
79 | 79 | } |
80 | 80 | |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | * |
87 | 87 | * @return $this |
88 | 88 | */ |
89 | - public function disconnect(){ |
|
89 | + public function disconnect() { |
|
90 | 90 | $this->db->close(); |
91 | 91 | } |
92 | 92 | |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | * |
96 | 96 | * @return string php's database client string |
97 | 97 | */ |
98 | - public function getClientInfo(){ |
|
98 | + public function getClientInfo() { |
|
99 | 99 | return $this->db->client_info; |
100 | 100 | } |
101 | 101 | |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | * |
105 | 105 | * @return string database's serverinfo string |
106 | 106 | */ |
107 | - public function getServerInfo(){ |
|
107 | + public function getServerInfo() { |
|
108 | 108 | return $this->db->server_info; |
109 | 109 | } |
110 | 110 | |
@@ -118,25 +118,25 @@ discard block |
||
118 | 118 | * |
119 | 119 | * @return array|string array or string. escaped. obviously. |
120 | 120 | */ |
121 | - public function escape($data, $specialchars = false){ |
|
121 | + public function escape($data, $specialchars = false) { |
|
122 | 122 | |
123 | - if(is_array($data)){ |
|
123 | + if (is_array($data)) { |
|
124 | 124 | |
125 | - foreach($data as $key => $value){ |
|
125 | + foreach ($data as $key => $value) { |
|
126 | 126 | $data[$key] = $this->escape($value, $specialchars); |
127 | 127 | } |
128 | 128 | |
129 | 129 | } |
130 | - else if(is_object($data)){ |
|
130 | + else if (is_object($data)) { |
|
131 | 131 | |
132 | - foreach($data as $key => $value){ |
|
132 | + foreach ($data as $key => $value) { |
|
133 | 133 | $data->{$key} = $this->escape($value, $specialchars); |
134 | 134 | } |
135 | 135 | |
136 | 136 | } |
137 | - else{ |
|
137 | + else { |
|
138 | 138 | |
139 | - if($specialchars){ |
|
139 | + if ($specialchars) { |
|
140 | 140 | $data = htmlspecialchars($data, ENT_HTML5, 'UTF-8', false); |
141 | 141 | } |
142 | 142 | |
@@ -163,9 +163,9 @@ discard block |
||
163 | 163 | * @return array|bool array with results, true on void query success, otherwise false. |
164 | 164 | * @throws \mysqli_sql_exception |
165 | 165 | */ |
166 | - public function raw($sql, $index = '', $assoc = true, $fetch_array = false){ |
|
166 | + public function raw($sql, $index = '', $assoc = true, $fetch_array = false) { |
|
167 | 167 | |
168 | - try{ |
|
168 | + try { |
|
169 | 169 | $result = $this->db->query($sql); |
170 | 170 | |
171 | 171 | $this->addStats([ |
@@ -178,21 +178,21 @@ discard block |
||
178 | 178 | 'fetch_array' => $fetch_array, |
179 | 179 | ]); |
180 | 180 | |
181 | - if(!is_bool($result)){ |
|
181 | + if (!is_bool($result)) { |
|
182 | 182 | $out = []; |
183 | 183 | $method = 'fetch_'.($assoc ? ($fetch_array ? 'assoc' : 'object') : 'row'); |
184 | - $i = 0 ; |
|
184 | + $i = 0; |
|
185 | 185 | |
186 | 186 | // ok, we have a result with one or more rows, loop out the rows and output as array |
187 | - while($row = $result->{$method}()){ |
|
187 | + while ($row = $result->{$method}()) { |
|
188 | 188 | $key = $i; |
189 | 189 | |
190 | - if($assoc && !empty($index)){ |
|
190 | + if ($assoc && !empty($index)) { |
|
191 | 191 | |
192 | - if($fetch_array && isset($row[$index])){ |
|
192 | + if ($fetch_array && isset($row[$index])) { |
|
193 | 193 | $key = $row[$index]; |
194 | 194 | } |
195 | - elseif(isset($row->{$index})){ |
|
195 | + elseif (isset($row->{$index})) { |
|
196 | 196 | $key = $row->{$index}; |
197 | 197 | } |
198 | 198 | |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | // void result |
211 | 211 | return $result; |
212 | 212 | } |
213 | - catch(mysqli_sql_exception $mysqli_sql_exception){ |
|
213 | + catch (mysqli_sql_exception $mysqli_sql_exception) { |
|
214 | 214 | throw $mysqli_sql_exception; |
215 | 215 | } |
216 | 216 | } |
@@ -225,10 +225,10 @@ discard block |
||
225 | 225 | * @return string |
226 | 226 | * @internal |
227 | 227 | */ |
228 | - protected function getTypes(array &$values){ |
|
228 | + protected function getTypes(array &$values) { |
|
229 | 229 | |
230 | - $types = array_map(function(&$v){ |
|
231 | - switch(gettype($v)){ |
|
230 | + $types = array_map(function(&$v) { |
|
231 | + switch (gettype($v)) { |
|
232 | 232 | case 'integer': return 'i'; |
233 | 233 | case 'double': return 'd'; |
234 | 234 | default: return 's'; |
@@ -252,18 +252,18 @@ discard block |
||
252 | 252 | * |
253 | 253 | * @return array|bool Array with results, true on void query success, otherwise false |
254 | 254 | */ |
255 | - public function prepared($sql, array $values = [], $index = '', $assoc = true, $fetch_array = false){ |
|
255 | + public function prepared($sql, array $values = [], $index = '', $assoc = true, $fetch_array = false) { |
|
256 | 256 | $stmt = $this->db->stmt_init(); |
257 | 257 | |
258 | - if($stmt->prepare($sql)){ |
|
258 | + if ($stmt->prepare($sql)) { |
|
259 | 259 | $reflectionClass = new ReflectionClass('mysqli_stmt'); |
260 | 260 | $types = $this->getTypes($values); |
261 | 261 | |
262 | - if(count($values) > 0){ |
|
262 | + if (count($values) > 0) { |
|
263 | 263 | // copy values to reference for bind_param's sake and put the types on top of the references array |
264 | 264 | // see http://php.net/manual/mysqli-stmt.bind-param.php |
265 | 265 | $references = []; |
266 | - foreach($values as &$field){ |
|
266 | + foreach ($values as &$field) { |
|
267 | 267 | $references[] = &$field; |
268 | 268 | } |
269 | 269 | |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | $metadata = $stmt->result_metadata(); |
290 | 290 | |
291 | 291 | // void result |
292 | - if(!$metadata){ |
|
292 | + if (!$metadata) { |
|
293 | 293 | return true; |
294 | 294 | } |
295 | 295 | |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | // http://php.net/manual/de/mysqli-stmt.bind-result.php |
298 | 298 | $cols = $refs = []; |
299 | 299 | |
300 | - foreach($metadata->fetch_fields() as $i => &$field){ |
|
300 | + foreach ($metadata->fetch_fields() as $i => &$field) { |
|
301 | 301 | $refs[] = &$cols[$assoc ? $field->name : $i]; |
302 | 302 | } |
303 | 303 | |
@@ -307,14 +307,14 @@ discard block |
||
307 | 307 | $output = []; |
308 | 308 | $count = 0; |
309 | 309 | |
310 | - while($stmt->fetch()){ |
|
310 | + while ($stmt->fetch()) { |
|
311 | 311 | $row = $fetch_array || !$assoc ? [] : new stdClass; |
312 | 312 | |
313 | - foreach($cols as $field => &$field){ |
|
314 | - if($fetch_array || !$assoc){ |
|
313 | + foreach ($cols as $field => &$field) { |
|
314 | + if ($fetch_array || !$assoc) { |
|
315 | 315 | $row[$field] = $field; |
316 | 316 | } |
317 | - else{ |
|
317 | + else { |
|
318 | 318 | $row->{$field} = $field; |
319 | 319 | } |
320 | 320 | } |
@@ -345,19 +345,19 @@ discard block |
||
345 | 345 | * |
346 | 346 | * @return bool true query success, otherwise false |
347 | 347 | */ |
348 | - public function multi($sql, array $values){ |
|
348 | + public function multi($sql, array $values) { |
|
349 | 349 | |
350 | - if(is_array($values) && count($values) > 0 && is_array($values[0]) && count($values[0]) > 0){ |
|
350 | + if (is_array($values) && count($values) > 0 && is_array($values[0]) && count($values[0]) > 0) { |
|
351 | 351 | $stmt = $this->db->stmt_init(); |
352 | 352 | |
353 | - if($stmt->prepare($sql)){ |
|
353 | + if ($stmt->prepare($sql)) { |
|
354 | 354 | $types = $this->getTypes($values[0]); |
355 | 355 | $method = (new ReflectionClass('mysqli_stmt'))->getMethod('bind_param'); |
356 | 356 | |
357 | - foreach($values as $row){ |
|
357 | + foreach ($values as $row) { |
|
358 | 358 | |
359 | 359 | $references = []; |
360 | - foreach($row as &$field){ |
|
360 | + foreach ($row as &$field) { |
|
361 | 361 | $references[] = &$field; |
362 | 362 | } |
363 | 363 |
@@ -126,15 +126,13 @@ discard block |
||
126 | 126 | $data[$key] = $this->escape($value, $specialchars); |
127 | 127 | } |
128 | 128 | |
129 | - } |
|
130 | - else if(is_object($data)){ |
|
129 | + } else if(is_object($data)){ |
|
131 | 130 | |
132 | 131 | foreach($data as $key => $value){ |
133 | 132 | $data->{$key} = $this->escape($value, $specialchars); |
134 | 133 | } |
135 | 134 | |
136 | - } |
|
137 | - else{ |
|
135 | + } else{ |
|
138 | 136 | |
139 | 137 | if($specialchars){ |
140 | 138 | $data = htmlspecialchars($data, ENT_HTML5, 'UTF-8', false); |
@@ -191,8 +189,7 @@ discard block |
||
191 | 189 | |
192 | 190 | if($fetch_array && isset($row[$index])){ |
193 | 191 | $key = $row[$index]; |
194 | - } |
|
195 | - elseif(isset($row->{$index})){ |
|
192 | + } elseif(isset($row->{$index})){ |
|
196 | 193 | $key = $row->{$index}; |
197 | 194 | } |
198 | 195 | |
@@ -209,8 +206,7 @@ discard block |
||
209 | 206 | |
210 | 207 | // void result |
211 | 208 | return $result; |
212 | - } |
|
213 | - catch(mysqli_sql_exception $mysqli_sql_exception){ |
|
209 | + } catch(mysqli_sql_exception $mysqli_sql_exception){ |
|
214 | 210 | throw $mysqli_sql_exception; |
215 | 211 | } |
216 | 212 | } |
@@ -313,8 +309,7 @@ discard block |
||
313 | 309 | foreach($cols as $field => &$field){ |
314 | 310 | if($fetch_array || !$assoc){ |
315 | 311 | $row[$field] = $field; |
316 | - } |
|
317 | - else{ |
|
312 | + } else{ |
|
318 | 313 | $row->{$field} = $field; |
319 | 314 | } |
320 | 315 | } |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | * |
24 | 24 | * @see http://php.net/manual/pdo.constants.php |
25 | 25 | */ |
26 | -class PDODriver extends DBBaseDriver implements DBDriverInterface{ |
|
26 | +class PDODriver extends DBBaseDriver implements DBDriverInterface { |
|
27 | 27 | |
28 | 28 | /** |
29 | 29 | * Holds the database resource object |
@@ -68,13 +68,13 @@ discard block |
||
68 | 68 | * |
69 | 69 | * @return string DSN |
70 | 70 | */ |
71 | - protected function getDSN(){ |
|
71 | + protected function getDSN() { |
|
72 | 72 | $dsn = $this->drivername; |
73 | 73 | |
74 | - if($this->options->socket){ |
|
74 | + if ($this->options->socket) { |
|
75 | 75 | $dsn .= ':unix_socket='.$this->options->socket; |
76 | 76 | } |
77 | - else{ |
|
77 | + else { |
|
78 | 78 | $dsn .= ':host='.$this->options->host; |
79 | 79 | $dsn .= (bool)$this->options->port ? ';port='.$this->options->port : ''; |
80 | 80 | } |
@@ -90,13 +90,13 @@ discard block |
||
90 | 90 | * @return \PDO the database resource object |
91 | 91 | * @throws \chillerlan\Database\DBException |
92 | 92 | */ |
93 | - public function connect(){ |
|
93 | + public function connect() { |
|
94 | 94 | |
95 | - if($this->db instanceof PDO){ |
|
95 | + if ($this->db instanceof PDO) { |
|
96 | 96 | return $this->db; |
97 | 97 | } |
98 | 98 | |
99 | - if($this->options->use_ssl){ |
|
99 | + if ($this->options->use_ssl) { |
|
100 | 100 | $this->pdo_options += [ |
101 | 101 | PDO::MYSQL_ATTR_SSL_KEY => $this->options->ssl_key, |
102 | 102 | PDO::MYSQL_ATTR_SSL_CERT => $this->options->ssl_cert, |
@@ -106,10 +106,10 @@ discard block |
||
106 | 106 | ]; |
107 | 107 | } |
108 | 108 | |
109 | - try{ |
|
109 | + try { |
|
110 | 110 | $this->db = new PDO($this->getDSN(), $this->options->username, $this->options->password, $this->pdo_options); |
111 | 111 | } |
112 | - catch(PDOException $PDOException){ |
|
112 | + catch (PDOException $PDOException) { |
|
113 | 113 | throw new DBException($PDOException->getMessage()); |
114 | 114 | } |
115 | 115 | |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | * |
122 | 122 | * @return $this |
123 | 123 | */ |
124 | - public function disconnect(){ |
|
124 | + public function disconnect() { |
|
125 | 125 | $this->db = null; |
126 | 126 | |
127 | 127 | return $this; |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | * |
133 | 133 | * @return string php's database client string |
134 | 134 | */ |
135 | - public function getClientInfo(){ |
|
135 | + public function getClientInfo() { |
|
136 | 136 | return $this->db->getAttribute(PDO::ATTR_CLIENT_VERSION); |
137 | 137 | } |
138 | 138 | |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | * |
142 | 142 | * @return string database's serverinfo string |
143 | 143 | */ |
144 | - public function getServerInfo(){ |
|
144 | + public function getServerInfo() { |
|
145 | 145 | return $this->db->getAttribute(PDO::ATTR_SERVER_INFO); |
146 | 146 | } |
147 | 147 | |
@@ -155,25 +155,25 @@ discard block |
||
155 | 155 | * |
156 | 156 | * @return array|string array or string. escaped. obviously. |
157 | 157 | */ |
158 | - public function escape($data, $specialchars = false){ |
|
158 | + public function escape($data, $specialchars = false) { |
|
159 | 159 | |
160 | - if(is_array($data)){ |
|
160 | + if (is_array($data)) { |
|
161 | 161 | |
162 | - foreach($data as $key => $value){ |
|
162 | + foreach ($data as $key => $value) { |
|
163 | 163 | $data[$key] = $this->escape($value, $specialchars); |
164 | 164 | } |
165 | 165 | |
166 | 166 | } |
167 | - else if(is_object($data)){ |
|
167 | + else if (is_object($data)) { |
|
168 | 168 | |
169 | - foreach($data as $key => $value){ |
|
169 | + foreach ($data as $key => $value) { |
|
170 | 170 | $data->{$key} = $this->escape($value, $specialchars); |
171 | 171 | } |
172 | 172 | |
173 | 173 | } |
174 | - else{ |
|
174 | + else { |
|
175 | 175 | |
176 | - if($specialchars){ |
|
176 | + if ($specialchars) { |
|
177 | 177 | $data = htmlspecialchars($data, ENT_HTML5, 'UTF-8', false); |
178 | 178 | } |
179 | 179 | |
@@ -192,21 +192,21 @@ discard block |
||
192 | 192 | * @return array |
193 | 193 | * @internal |
194 | 194 | */ |
195 | - protected function getResult(PDOStatement &$stmt, $index, $assoc, $fetch_array){ |
|
195 | + protected function getResult(PDOStatement&$stmt, $index, $assoc, $fetch_array) { |
|
196 | 196 | $out = []; |
197 | 197 | $method = $assoc ? ($fetch_array ? PDO::FETCH_ASSOC : PDO::FETCH_OBJ) : PDO::FETCH_NUM; |
198 | - $i = 0 ; |
|
198 | + $i = 0; |
|
199 | 199 | |
200 | 200 | // ok, we have a result with one or more rows, loop out the rows and output as array |
201 | - while($row = $stmt->fetch($method)){ |
|
201 | + while ($row = $stmt->fetch($method)) { |
|
202 | 202 | $key = $i; |
203 | 203 | |
204 | - if($assoc && !empty($index)){ |
|
204 | + if ($assoc && !empty($index)) { |
|
205 | 205 | |
206 | - if($fetch_array && isset($row[$index])){ |
|
206 | + if ($fetch_array && isset($row[$index])) { |
|
207 | 207 | $key = $row[$index]; |
208 | 208 | } |
209 | - else if(isset($row->{$index})){ |
|
209 | + else if (isset($row->{$index})) { |
|
210 | 210 | $key = $row->{$index}; |
211 | 211 | } |
212 | 212 | |
@@ -225,16 +225,16 @@ discard block |
||
225 | 225 | * @param array $values |
226 | 226 | * @internal |
227 | 227 | */ |
228 | - protected function bindParams(PDOStatement &$stmt, array $values){ |
|
228 | + protected function bindParams(PDOStatement&$stmt, array $values) { |
|
229 | 229 | $param_no = 1; |
230 | 230 | |
231 | - foreach($values as $v){ |
|
231 | + foreach ($values as $v) { |
|
232 | 232 | |
233 | - switch(gettype($v)){ |
|
233 | + switch (gettype($v)) { |
|
234 | 234 | case 'boolean': $type = PDO::PARAM_BOOL; break; |
235 | - case 'integer': $type = PDO::PARAM_INT; break; |
|
235 | + case 'integer': $type = PDO::PARAM_INT; break; |
|
236 | 236 | case 'NULL': $type = PDO::PARAM_NULL; break; |
237 | - default: $type = PDO::PARAM_STR; break; |
|
237 | + default: $type = PDO::PARAM_STR; break; |
|
238 | 238 | } |
239 | 239 | |
240 | 240 | $stmt->bindValue($param_no, $v, $type); |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | * @link http://php.net/manual/pdo.lastinsertid.php |
249 | 249 | * @return string |
250 | 250 | */ |
251 | - protected function insertID(){ |
|
251 | + protected function insertID() { |
|
252 | 252 | return $this->db->lastInsertId(); |
253 | 253 | } |
254 | 254 | |
@@ -269,9 +269,9 @@ discard block |
||
269 | 269 | * @return array|bool array with results, true on void query success, otherwise false. |
270 | 270 | * @throws \PDOException |
271 | 271 | */ |
272 | - public function raw($sql, $index = '', $assoc = true, $fetch_array = false){ |
|
272 | + public function raw($sql, $index = '', $assoc = true, $fetch_array = false) { |
|
273 | 273 | |
274 | - try{ |
|
274 | + try { |
|
275 | 275 | $stmt = $this->db->query($sql); |
276 | 276 | |
277 | 277 | $this->addStats([ |
@@ -284,14 +284,14 @@ discard block |
||
284 | 284 | 'fetch_array' => $fetch_array, |
285 | 285 | ]); |
286 | 286 | |
287 | - if(!is_bool($stmt)){ |
|
287 | + if (!is_bool($stmt)) { |
|
288 | 288 | return $this->getResult($stmt, $index, $assoc, $fetch_array); |
289 | 289 | } |
290 | 290 | |
291 | 291 | // void result |
292 | 292 | return $stmt; |
293 | 293 | } |
294 | - catch(PDOException $PDOException){ |
|
294 | + catch (PDOException $PDOException) { |
|
295 | 295 | throw $PDOException; |
296 | 296 | } |
297 | 297 | |
@@ -312,12 +312,12 @@ discard block |
||
312 | 312 | * @return array|bool Array with results, true on void query success, otherwise false |
313 | 313 | * @throws \PDOException |
314 | 314 | */ |
315 | - public function prepared($sql, array $values = [], $index = '', $assoc = true, $fetch_array = false){ |
|
315 | + public function prepared($sql, array $values = [], $index = '', $assoc = true, $fetch_array = false) { |
|
316 | 316 | |
317 | - try{ |
|
317 | + try { |
|
318 | 318 | $stmt = $this->db->prepare($sql, $this->pdo_stmt_options); |
319 | 319 | |
320 | - if(!empty($values)){ |
|
320 | + if (!empty($values)) { |
|
321 | 321 | $this->bindParams($stmt, $values); |
322 | 322 | } |
323 | 323 | |
@@ -334,13 +334,13 @@ discard block |
||
334 | 334 | 'fetch_array' => $fetch_array, |
335 | 335 | ]); |
336 | 336 | |
337 | - if(!is_bool($stmt)){ |
|
337 | + if (!is_bool($stmt)) { |
|
338 | 338 | return $this->getResult($stmt, $index, $assoc, $fetch_array); |
339 | 339 | } |
340 | 340 | |
341 | 341 | return $stmt; |
342 | 342 | } |
343 | - catch(PDOException $PDOException){ |
|
343 | + catch (PDOException $PDOException) { |
|
344 | 344 | throw $PDOException; |
345 | 345 | } |
346 | 346 | } |
@@ -355,12 +355,12 @@ discard block |
||
355 | 355 | * |
356 | 356 | * @return bool true query success, otherwise false |
357 | 357 | */ |
358 | - public function multi($sql, array $values){ |
|
358 | + public function multi($sql, array $values) { |
|
359 | 359 | |
360 | - if(is_array($values) && count($values) > 0 && is_array($values[0]) && count($values[0]) > 0){ |
|
360 | + if (is_array($values) && count($values) > 0 && is_array($values[0]) && count($values[0]) > 0) { |
|
361 | 361 | $stmt = $this->db->prepare($sql, $this->pdo_stmt_options); |
362 | 362 | |
363 | - foreach($values as $row){ |
|
363 | + foreach ($values as $row) { |
|
364 | 364 | $this->bindParams($stmt, $row); |
365 | 365 | $stmt->execute(); |
366 | 366 |
@@ -73,8 +73,7 @@ discard block |
||
73 | 73 | |
74 | 74 | if($this->options->socket){ |
75 | 75 | $dsn .= ':unix_socket='.$this->options->socket; |
76 | - } |
|
77 | - else{ |
|
76 | + } else{ |
|
78 | 77 | $dsn .= ':host='.$this->options->host; |
79 | 78 | $dsn .= (bool)$this->options->port ? ';port='.$this->options->port : ''; |
80 | 79 | } |
@@ -108,8 +107,7 @@ discard block |
||
108 | 107 | |
109 | 108 | try{ |
110 | 109 | $this->db = new PDO($this->getDSN(), $this->options->username, $this->options->password, $this->pdo_options); |
111 | - } |
|
112 | - catch(PDOException $PDOException){ |
|
110 | + } catch(PDOException $PDOException){ |
|
113 | 111 | throw new DBException($PDOException->getMessage()); |
114 | 112 | } |
115 | 113 | |
@@ -163,15 +161,13 @@ discard block |
||
163 | 161 | $data[$key] = $this->escape($value, $specialchars); |
164 | 162 | } |
165 | 163 | |
166 | - } |
|
167 | - else if(is_object($data)){ |
|
164 | + } else if(is_object($data)){ |
|
168 | 165 | |
169 | 166 | foreach($data as $key => $value){ |
170 | 167 | $data->{$key} = $this->escape($value, $specialchars); |
171 | 168 | } |
172 | 169 | |
173 | - } |
|
174 | - else{ |
|
170 | + } else{ |
|
175 | 171 | |
176 | 172 | if($specialchars){ |
177 | 173 | $data = htmlspecialchars($data, ENT_HTML5, 'UTF-8', false); |
@@ -205,8 +201,7 @@ discard block |
||
205 | 201 | |
206 | 202 | if($fetch_array && isset($row[$index])){ |
207 | 203 | $key = $row[$index]; |
208 | - } |
|
209 | - else if(isset($row->{$index})){ |
|
204 | + } else if(isset($row->{$index})){ |
|
210 | 205 | $key = $row->{$index}; |
211 | 206 | } |
212 | 207 | |
@@ -290,8 +285,7 @@ discard block |
||
290 | 285 | |
291 | 286 | // void result |
292 | 287 | return $stmt; |
293 | - } |
|
294 | - catch(PDOException $PDOException){ |
|
288 | + } catch(PDOException $PDOException){ |
|
295 | 289 | throw $PDOException; |
296 | 290 | } |
297 | 291 | |
@@ -339,8 +333,7 @@ discard block |
||
339 | 333 | } |
340 | 334 | |
341 | 335 | return $stmt; |
342 | - } |
|
343 | - catch(PDOException $PDOException){ |
|
336 | + } catch(PDOException $PDOException){ |
|
344 | 337 | throw $PDOException; |
345 | 338 | } |
346 | 339 | } |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | /** |
16 | 16 | * Class PDOFirebirdDriver |
17 | 17 | */ |
18 | -class PDOFirebirdDriver extends PDODriver implements DBDriverInterface{ |
|
18 | +class PDOFirebirdDriver extends PDODriver implements DBDriverInterface { |
|
19 | 19 | |
20 | 20 | /** |
21 | 21 | * The PDO drivername which is being used in the DSN |
@@ -30,13 +30,13 @@ discard block |
||
30 | 30 | * |
31 | 31 | * @return string DSN |
32 | 32 | */ |
33 | - protected function getDSN(){ |
|
33 | + protected function getDSN() { |
|
34 | 34 | $dsn = $this->drivername.':dbname='; |
35 | 35 | |
36 | - if((bool)$this->options->host){ |
|
36 | + if ((bool)$this->options->host) { |
|
37 | 37 | $dsn .= $this->options->host; |
38 | 38 | |
39 | - if((bool)$this->options->port){ |
|
39 | + if ((bool)$this->options->port) { |
|
40 | 40 | $dsn .= '/'.$this->options->port; |
41 | 41 | } |
42 | 42 | |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | * @link http://php.net/manual/pdo.lastinsertid.php |
57 | 57 | * @return null |
58 | 58 | */ |
59 | - protected function insertID(){ |
|
59 | + protected function insertID() { |
|
60 | 60 | return null; |
61 | 61 | } |
62 | 62 |