@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | public $database = ''; |
20 | 20 | public $user = ''; |
21 | 21 | public $password = ''; |
22 | - public $port = ''; |
|
22 | + public $port = ''; |
|
23 | 23 | |
24 | 24 | /* public: configuration parameters */ |
25 | 25 | public $autoStripslashes = false; |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | * @param string $password Optional The password to use |
70 | 70 | * @param string $host Optional The hostname where the server is, or default to localhost |
71 | 71 | * @param string $query Optional query to perform immediately |
72 | - * @param string $port optional port for the connection |
|
72 | + * @param string $port optional port for the connection |
|
73 | 73 | */ |
74 | 74 | public function __construct($database = '', $user = '', $password = '', $host = 'localhost', $query = '', $port = '') |
75 | 75 | { |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | $this->user = $user; |
78 | 78 | $this->password = $password; |
79 | 79 | $this->host = $host; |
80 | - $this->port = $port; |
|
80 | + $this->port = $port; |
|
81 | 81 | if ($query != '') { |
82 | 82 | $this->query($query); |
83 | 83 | } |
@@ -12,8 +12,7 @@ discard block |
||
12 | 12 | /** |
13 | 13 | * Class Generic |
14 | 14 | */ |
15 | -abstract class Generic |
|
16 | -{ |
|
15 | +abstract class Generic { |
|
17 | 16 | /* public: connection parameters */ |
18 | 17 | public $host = 'localhost'; |
19 | 18 | public $database = ''; |
@@ -71,8 +70,7 @@ discard block |
||
71 | 70 | * @param string $query Optional query to perform immediately |
72 | 71 | * @param string $port optional port for the connection |
73 | 72 | */ |
74 | - public function __construct($database = '', $user = '', $password = '', $host = 'localhost', $query = '', $port = '') |
|
75 | - { |
|
73 | + public function __construct($database = '', $user = '', $password = '', $host = 'localhost', $query = '', $port = '') { |
|
76 | 74 | $this->database = $database; |
77 | 75 | $this->user = $user; |
78 | 76 | $this->password = $password; |
@@ -90,24 +88,21 @@ discard block |
||
90 | 88 | * @param string $file |
91 | 89 | * @return void |
92 | 90 | */ |
93 | - public function log($message, $line = '', $file = '', $level = 'info') |
|
94 | - { |
|
91 | + public function log($message, $line = '', $file = '', $level = 'info') { |
|
95 | 92 | error_log($message); |
96 | 93 | } |
97 | 94 | |
98 | 95 | /** |
99 | 96 | * @return int|object |
100 | 97 | */ |
101 | - public function linkId() |
|
102 | - { |
|
98 | + public function linkId() { |
|
103 | 99 | return $this->linkId; |
104 | 100 | } |
105 | 101 | |
106 | 102 | /** |
107 | 103 | * @return int|object |
108 | 104 | */ |
109 | - public function queryId() |
|
110 | - { |
|
105 | + public function queryId() { |
|
111 | 106 | return $this->queryId; |
112 | 107 | } |
113 | 108 | |
@@ -115,8 +110,7 @@ discard block |
||
115 | 110 | * @param $string |
116 | 111 | * @return string |
117 | 112 | */ |
118 | - public function real_escape($string = '') |
|
119 | - { |
|
113 | + public function real_escape($string = '') { |
|
120 | 114 | if ((!is_resource($this->linkId) || $this->linkId == 0) && !$this->connect()) { |
121 | 115 | return $this->escape($string); |
122 | 116 | } |
@@ -127,8 +121,7 @@ discard block |
||
127 | 121 | * @param $string |
128 | 122 | * @return string |
129 | 123 | */ |
130 | - public function escape($string = '') |
|
131 | - { |
|
124 | + public function escape($string = '') { |
|
132 | 125 | //if (function_exists('mysql_escape_string')) |
133 | 126 | //return mysql_escape_string($string); |
134 | 127 | return str_replace(array('\\', "\0", "\n", "\r", "'", '"', "\x1a"), array('\\\\', '\\0', '\\n', '\\r', "\\'", '\\"', '\\Z'), $string); |
@@ -138,8 +131,7 @@ discard block |
||
138 | 131 | * @param mixed $str |
139 | 132 | * @return string |
140 | 133 | */ |
141 | - public function dbAddslashes($str = '') |
|
142 | - { |
|
134 | + public function dbAddslashes($str = '') { |
|
143 | 135 | if (!isset($str) || $str == '') { |
144 | 136 | return ''; |
145 | 137 | } |
@@ -151,8 +143,7 @@ discard block |
||
151 | 143 | * @param mixed $epoch |
152 | 144 | * @return bool|string |
153 | 145 | */ |
154 | - public function toTimestamp($epoch) |
|
155 | - { |
|
146 | + public function toTimestamp($epoch) { |
|
156 | 147 | return date('Y-m-d H:i:s', $epoch); |
157 | 148 | } |
158 | 149 | |
@@ -161,8 +152,7 @@ discard block |
||
161 | 152 | * @param mixed $timestamp |
162 | 153 | * @return bool|int|mixed |
163 | 154 | */ |
164 | - public function fromTimestamp($timestamp) |
|
165 | - { |
|
155 | + public function fromTimestamp($timestamp) { |
|
166 | 156 | if (preg_match('/([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})/', $timestamp, $parts)) { |
167 | 157 | $time = mktime($parts[4], $parts[5], $parts[6], $parts[2], $parts[3], $parts[1]); |
168 | 158 | } elseif (preg_match('/([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/', $timestamp, $parts)) { |
@@ -188,8 +178,7 @@ discard block |
||
188 | 178 | * @param string $file |
189 | 179 | * @return mixed |
190 | 180 | */ |
191 | - public function limitQuery($queryString, $numRows = '', $offset = 0, $line = '', $file = '') |
|
192 | - { |
|
181 | + public function limitQuery($queryString, $numRows = '', $offset = 0, $line = '', $file = '') { |
|
193 | 182 | if (!$numRows) { |
194 | 183 | $numRows = $this->maxMatches; |
195 | 184 | } |
@@ -216,8 +205,7 @@ discard block |
||
216 | 205 | * @param string $file optionally pass __FILE__ calling the query for logging |
217 | 206 | * @return mixed FALSE if no rows, if a single row it returns that, if multiple it returns an array of rows, associative responses only |
218 | 207 | */ |
219 | - public function qr($query, $line = '', $file = '') |
|
220 | - { |
|
208 | + public function qr($query, $line = '', $file = '') { |
|
221 | 209 | return $this->queryReturn($query, $line, $file); |
222 | 210 | } |
223 | 211 | |
@@ -228,8 +216,7 @@ discard block |
||
228 | 216 | * @param string $stripSlashes |
229 | 217 | * @return string |
230 | 218 | */ |
231 | - public function f($name, $stripSlashes = '') |
|
232 | - { |
|
219 | + public function f($name, $stripSlashes = '') { |
|
233 | 220 | if ($stripSlashes || ($this->autoStripslashes && !$stripSlashes)) { |
234 | 221 | return stripslashes($this->Record[$name]); |
235 | 222 | } else { |
@@ -245,8 +232,7 @@ discard block |
||
245 | 232 | * @param string $file |
246 | 233 | * @return void |
247 | 234 | */ |
248 | - public function halt($msg, $line = '', $file = '') |
|
249 | - { |
|
235 | + public function halt($msg, $line = '', $file = '') { |
|
250 | 236 | $this->unlock(false); |
251 | 237 | /* Just in case there is a table currently locked */ |
252 | 238 | |
@@ -274,8 +260,7 @@ discard block |
||
274 | 260 | * @param string $file |
275 | 261 | * @return mixed|void |
276 | 262 | */ |
277 | - public function logBackTrace($msg, $line = '', $file = '') |
|
278 | - { |
|
263 | + public function logBackTrace($msg, $line = '', $file = '') { |
|
279 | 264 | $backtrace = (function_exists('debug_backtrace') ? debug_backtrace() : []); |
280 | 265 | $this->log( |
281 | 266 | ('' !== getenv('REQUEST_URI') ? ' '.getenv('REQUEST_URI') : ''). |
@@ -306,8 +291,7 @@ discard block |
||
306 | 291 | } |
307 | 292 | } |
308 | 293 | |
309 | - public function emailError($queryString, $error, $line, $file) |
|
310 | - { |
|
294 | + public function emailError($queryString, $error, $line, $file) { |
|
311 | 295 | $subject = php_uname('n').' MySQLi Error'; |
312 | 296 | $smarty = new \TFSmarty(); |
313 | 297 | $smarty->assign([ |
@@ -334,8 +318,7 @@ discard block |
||
334 | 318 | * @param string $file |
335 | 319 | * @return mixed|void |
336 | 320 | */ |
337 | - public function haltmsg($msg, $line = '', $file = '') |
|
338 | - { |
|
321 | + public function haltmsg($msg, $line = '', $file = '') { |
|
339 | 322 | $this->log("Database error: $msg", $line, $file, 'error'); |
340 | 323 | if ($this->Errno != '0' || !in_array($this->Error, ['', '()'])) { |
341 | 324 | $sqlstate = mysqli_sqlstate($this->linkId); |
@@ -347,8 +330,7 @@ discard block |
||
347 | 330 | /** |
348 | 331 | * @return array |
349 | 332 | */ |
350 | - public function indexNames() |
|
351 | - { |
|
333 | + public function indexNames() { |
|
352 | 334 | return []; |
353 | 335 | } |
354 | 336 | |
@@ -360,8 +342,7 @@ discard block |
||
360 | 342 | * @param string|int $line Line Number |
361 | 343 | * @param string $file File Name |
362 | 344 | */ |
363 | - public function addLog($statement, $time, $line = '', $file = '') |
|
364 | - { |
|
345 | + public function addLog($statement, $time, $line = '', $file = '') { |
|
365 | 346 | $query = [ |
366 | 347 | 'statement' => $statement, |
367 | 348 | 'time' => $time * 1000 |
@@ -383,8 +364,7 @@ discard block |
||
383 | 364 | * Return logged queries. |
384 | 365 | * @return array Logged queries |
385 | 366 | */ |
386 | - public function getLog() |
|
387 | - { |
|
367 | + public function getLog() { |
|
388 | 368 | return $this->log; |
389 | 369 | } |
390 | 370 | } |
@@ -69,12 +69,12 @@ discard block |
||
69 | 69 | if ($user == '') { |
70 | 70 | $user = $this->user; |
71 | 71 | } |
72 | - if ($password == '') { |
|
73 | - $password = $this->password; |
|
74 | - } |
|
75 | - if ($port == '') { |
|
76 | - $port = $this->port; |
|
77 | - } |
|
72 | + if ($password == '') { |
|
73 | + $password = $this->password; |
|
74 | + } |
|
75 | + if ($port == '') { |
|
76 | + $port = $this->port; |
|
77 | + } |
|
78 | 78 | /* establish connection, select database */ |
79 | 79 | if (!is_object($this->linkId)) { |
80 | 80 | $this->connectionAttempt++; |
@@ -87,11 +87,11 @@ discard block |
||
87 | 87 | } |
88 | 88 | $this->linkId = mysqli_init(); |
89 | 89 | $this->linkId->options(MYSQLI_INIT_COMMAND, "SET NAMES {$this->characterSet} COLLATE {$this->collation}, COLLATION_CONNECTION = {$this->collation}, COLLATION_DATABASE = {$this->collation}"); |
90 | - if ($port != '') { |
|
91 | - $this->linkId->real_connect($host, $user, $password, $database, $port); |
|
92 | - } else { |
|
93 | - $this->linkId->real_connect($host, $user, $password, $database); |
|
94 | - } |
|
90 | + if ($port != '') { |
|
91 | + $this->linkId->real_connect($host, $user, $password, $database, $port); |
|
92 | + } else { |
|
93 | + $this->linkId->real_connect($host, $user, $password, $database); |
|
94 | + } |
|
95 | 95 | $this->linkId->set_charset($this->characterSet); |
96 | 96 | if ($this->linkId->connect_errno) { |
97 | 97 | $this->halt("connect($host, $user, \$password) failed. ".$mysqli->connect_error); |
@@ -17,8 +17,7 @@ discard block |
||
17 | 17 | * |
18 | 18 | * @access public |
19 | 19 | */ |
20 | -class Db extends Generic implements Db_Interface |
|
21 | -{ |
|
20 | +class Db extends Generic implements Db_Interface { |
|
22 | 21 | /** |
23 | 22 | * @var string |
24 | 23 | */ |
@@ -30,8 +29,7 @@ discard block |
||
30 | 29 | * @param string $database the name of the database to use |
31 | 30 | * @return void |
32 | 31 | */ |
33 | - public function useDb($database) |
|
34 | - { |
|
32 | + public function useDb($database) { |
|
35 | 33 | $this->selectDb($database); |
36 | 34 | } |
37 | 35 | |
@@ -41,8 +39,7 @@ discard block |
||
41 | 39 | * @param string $database the name of the database to use |
42 | 40 | * @return void |
43 | 41 | */ |
44 | - public function selectDb($database) |
|
45 | - { |
|
42 | + public function selectDb($database) { |
|
46 | 43 | $this->connect(); |
47 | 44 | mysqli_select_db($this->linkId, $database); |
48 | 45 | } |
@@ -57,8 +54,7 @@ discard block |
||
57 | 54 | * @param string $password |
58 | 55 | * @return int|\mysqli |
59 | 56 | */ |
60 | - public function connect($database = '', $host = '', $user = '', $password = '', $port = '') |
|
61 | - { |
|
57 | + public function connect($database = '', $host = '', $user = '', $password = '', $port = '') { |
|
62 | 58 | /* Handle defaults */ |
63 | 59 | if ($database == '') { |
64 | 60 | $database = $this->database; |
@@ -105,8 +101,7 @@ discard block |
||
105 | 101 | * Db::disconnect() |
106 | 102 | * @return bool |
107 | 103 | */ |
108 | - public function disconnect() |
|
109 | - { |
|
104 | + public function disconnect() { |
|
110 | 105 | $return = method_exists($this->linkId, 'close') ? $this->linkId->close() : false; |
111 | 106 | $this->linkId = 0; |
112 | 107 | return $return; |
@@ -116,8 +111,7 @@ discard block |
||
116 | 111 | * @param $string |
117 | 112 | * @return string |
118 | 113 | */ |
119 | - public function real_escape($string = '') |
|
120 | - { |
|
114 | + public function real_escape($string = '') { |
|
121 | 115 | if ((!is_resource($this->linkId) || $this->linkId == 0) && !$this->connect()) { |
122 | 116 | return $this->escape($string); |
123 | 117 | } |
@@ -128,8 +122,7 @@ discard block |
||
128 | 122 | * discard the query result |
129 | 123 | * @return void |
130 | 124 | */ |
131 | - public function free() |
|
132 | - { |
|
125 | + public function free() { |
|
133 | 126 | if (is_resource($this->queryId)) { |
134 | 127 | @mysqli_free_result($this->queryId); |
135 | 128 | } |
@@ -147,8 +140,7 @@ discard block |
||
147 | 140 | * @param string $file optionally pass __FILE__ calling the query for logging |
148 | 141 | * @return mixed FALSE if no rows, if a single row it returns that, if multiple it returns an array of rows, associative responses only |
149 | 142 | */ |
150 | - public function queryReturn($query, $line = '', $file = '') |
|
151 | - { |
|
143 | + public function queryReturn($query, $line = '', $file = '') { |
|
152 | 144 | $this->query($query, $line, $file); |
153 | 145 | if ($this->num_rows() == 0) { |
154 | 146 | return false; |
@@ -174,8 +166,7 @@ discard block |
||
174 | 166 | * @param string $file optionally pass __FILE__ calling the query for logging |
175 | 167 | * @return mixed FALSE if no rows, if a single row it returns that, if multiple it returns an array of rows, associative responses only |
176 | 168 | */ |
177 | - public function qr($query, $line = '', $file = '') |
|
178 | - { |
|
169 | + public function qr($query, $line = '', $file = '') { |
|
179 | 170 | return $this->queryReturn($query, $line, $file); |
180 | 171 | } |
181 | 172 | |
@@ -187,8 +178,7 @@ discard block |
||
187 | 178 | * @param string $line |
188 | 179 | * @param string $file |
189 | 180 | */ |
190 | - public function prepare($query, $line = '', $file = '') |
|
191 | - { |
|
181 | + public function prepare($query, $line = '', $file = '') { |
|
192 | 182 | if (!$this->connect()) { |
193 | 183 | return 0; |
194 | 184 | } |
@@ -210,8 +200,7 @@ discard block |
||
210 | 200 | * @param string $file |
211 | 201 | * @return mixed 0 if no query or query id handler, safe to ignore this return |
212 | 202 | */ |
213 | - public function query($queryString, $line = '', $file = '') |
|
214 | - { |
|
203 | + public function query($queryString, $line = '', $file = '') { |
|
215 | 204 | /* No empty queries, please, since PHP4 chokes on them. */ |
216 | 205 | /* The empty query string is passed on from the constructor, |
217 | 206 | * when calling the class without a query, e.g. in situations |
@@ -267,8 +256,7 @@ discard block |
||
267 | 256 | /** |
268 | 257 | * @return array|null|object |
269 | 258 | */ |
270 | - public function fetchObject() |
|
271 | - { |
|
259 | + public function fetchObject() { |
|
272 | 260 | $this->Record = @mysqli_fetch_object($this->queryId); |
273 | 261 | return $this->Record; |
274 | 262 | } |
@@ -281,8 +269,7 @@ discard block |
||
281 | 269 | * @param mixed $resultType |
282 | 270 | * @return bool |
283 | 271 | */ |
284 | - public function next_record($resultType = MYSQLI_BOTH) |
|
285 | - { |
|
272 | + public function next_record($resultType = MYSQLI_BOTH) { |
|
286 | 273 | if ($this->queryId === false) { |
287 | 274 | $this->haltmsg('next_record called with no query pending.'); |
288 | 275 | return 0; |
@@ -306,8 +293,7 @@ discard block |
||
306 | 293 | * @param integer $pos the row numbe starting at 0 to switch to |
307 | 294 | * @return bool whetherit was successfu or not. |
308 | 295 | */ |
309 | - public function seek($pos = 0) |
|
310 | - { |
|
296 | + public function seek($pos = 0) { |
|
311 | 297 | $status = @mysqli_data_seek($this->queryId, $pos); |
312 | 298 | if ($status) { |
313 | 299 | $this->Row = $pos; |
@@ -327,8 +313,7 @@ discard block |
||
327 | 313 | * |
328 | 314 | * @return bool |
329 | 315 | */ |
330 | - public function transactionBegin() |
|
331 | - { |
|
316 | + public function transactionBegin() { |
|
332 | 317 | if (version_compare(PHP_VERSION, '5.5.0') < 0) { |
333 | 318 | return true; |
334 | 319 | } |
@@ -343,8 +328,7 @@ discard block |
||
343 | 328 | * |
344 | 329 | * @return bool |
345 | 330 | */ |
346 | - public function transactionCommit() |
|
347 | - { |
|
331 | + public function transactionCommit() { |
|
348 | 332 | if (version_compare(PHP_VERSION, '5.5.0') < 0 || $this->linkId === 0) { |
349 | 333 | return true; |
350 | 334 | } |
@@ -356,8 +340,7 @@ discard block |
||
356 | 340 | * |
357 | 341 | * @return bool |
358 | 342 | */ |
359 | - public function transactionAbort() |
|
360 | - { |
|
343 | + public function transactionAbort() { |
|
361 | 344 | if (version_compare(PHP_VERSION, '5.5.0') < 0 || $this->linkId === 0) { |
362 | 345 | return true; |
363 | 346 | } |
@@ -373,8 +356,7 @@ discard block |
||
373 | 356 | * @param string $field |
374 | 357 | * @return int|string |
375 | 358 | */ |
376 | - public function getLastInsertId($table, $field) |
|
377 | - { |
|
359 | + public function getLastInsertId($table, $field) { |
|
378 | 360 | if (!isset($table) || $table == '' || !isset($field) || $field == '') { |
379 | 361 | return -1; |
380 | 362 | } |
@@ -390,8 +372,7 @@ discard block |
||
390 | 372 | * @param string $mode |
391 | 373 | * @return bool|int|\mysqli_result |
392 | 374 | */ |
393 | - public function lock($table, $mode = 'write') |
|
394 | - { |
|
375 | + public function lock($table, $mode = 'write') { |
|
395 | 376 | $this->connect(); |
396 | 377 | $query = 'lock tables '; |
397 | 378 | if (is_array($table)) { |
@@ -419,8 +400,7 @@ discard block |
||
419 | 400 | * @param bool $haltOnError optional, defaults to TRUE, whether or not to halt on error |
420 | 401 | * @return bool|int|\mysqli_result |
421 | 402 | */ |
422 | - public function unlock($haltOnError = true) |
|
423 | - { |
|
403 | + public function unlock($haltOnError = true) { |
|
424 | 404 | $this->connect(); |
425 | 405 | |
426 | 406 | $res = @mysqli_query($this->linkId, 'unlock tables'); |
@@ -437,8 +417,7 @@ discard block |
||
437 | 417 | * Db::affectedRows() |
438 | 418 | * @return int |
439 | 419 | */ |
440 | - public function affectedRows() |
|
441 | - { |
|
420 | + public function affectedRows() { |
|
442 | 421 | return @mysqli_affected_rows($this->linkId); |
443 | 422 | } |
444 | 423 | |
@@ -446,8 +425,7 @@ discard block |
||
446 | 425 | * Db::num_rows() |
447 | 426 | * @return int |
448 | 427 | */ |
449 | - public function num_rows() |
|
450 | - { |
|
428 | + public function num_rows() { |
|
451 | 429 | return @mysqli_num_rows($this->queryId); |
452 | 430 | } |
453 | 431 | |
@@ -455,8 +433,7 @@ discard block |
||
455 | 433 | * Db::num_fields() |
456 | 434 | * @return int |
457 | 435 | */ |
458 | - public function num_fields() |
|
459 | - { |
|
436 | + public function num_fields() { |
|
460 | 437 | return @mysqli_num_fields($this->queryId); |
461 | 438 | } |
462 | 439 | |
@@ -465,8 +442,7 @@ discard block |
||
465 | 442 | * |
466 | 443 | * @return array |
467 | 444 | */ |
468 | - public function tableNames() |
|
469 | - { |
|
445 | + public function tableNames() { |
|
470 | 446 | $return = []; |
471 | 447 | $this->query('SHOW TABLES'); |
472 | 448 | $i = 0; |