@@ -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 = ''; |
@@ -69,8 +68,7 @@ discard block |
||
| 69 | 68 | * @param string $host Optional The hostname where the server is, or default to localhost |
| 70 | 69 | * @param string $query Optional query to perform immediately |
| 71 | 70 | */ |
| 72 | - public function __construct($database = '', $user = '', $password = '', $host = 'localhost', $query = '') |
|
| 73 | - { |
|
| 71 | + public function __construct($database = '', $user = '', $password = '', $host = 'localhost', $query = '') { |
|
| 74 | 72 | $this->database = $database; |
| 75 | 73 | $this->user = $user; |
| 76 | 74 | $this->password = $password; |
@@ -87,24 +85,21 @@ discard block |
||
| 87 | 85 | * @param string $file |
| 88 | 86 | * @return void |
| 89 | 87 | */ |
| 90 | - public function log($message, $line = '', $file = '', $level = 'info') |
|
| 91 | - { |
|
| 88 | + public function log($message, $line = '', $file = '', $level = 'info') { |
|
| 92 | 89 | error_log($message); |
| 93 | 90 | } |
| 94 | 91 | |
| 95 | 92 | /** |
| 96 | 93 | * @return int|object |
| 97 | 94 | */ |
| 98 | - public function linkId() |
|
| 99 | - { |
|
| 95 | + public function linkId() { |
|
| 100 | 96 | return $this->linkId; |
| 101 | 97 | } |
| 102 | 98 | |
| 103 | 99 | /** |
| 104 | 100 | * @return int|object |
| 105 | 101 | */ |
| 106 | - public function queryId() |
|
| 107 | - { |
|
| 102 | + public function queryId() { |
|
| 108 | 103 | return $this->queryId; |
| 109 | 104 | } |
| 110 | 105 | |
@@ -112,8 +107,7 @@ discard block |
||
| 112 | 107 | * @param $string |
| 113 | 108 | * @return string |
| 114 | 109 | */ |
| 115 | - public function real_escape($string = '') |
|
| 116 | - { |
|
| 110 | + public function real_escape($string = '') { |
|
| 117 | 111 | if ((!is_resource($this->linkId) || $this->linkId == 0) && !$this->connect()) { |
| 118 | 112 | return $this->escape($string); |
| 119 | 113 | } |
@@ -124,8 +118,7 @@ discard block |
||
| 124 | 118 | * @param $string |
| 125 | 119 | * @return string |
| 126 | 120 | */ |
| 127 | - public function escape($string = '') |
|
| 128 | - { |
|
| 121 | + public function escape($string = '') { |
|
| 129 | 122 | //if (function_exists('mysql_escape_string')) |
| 130 | 123 | //return mysql_escape_string($string); |
| 131 | 124 | return str_replace(array('\\', "\0", "\n", "\r", "'", '"', "\x1a"), array('\\\\', '\\0', '\\n', '\\r', "\\'", '\\"', '\\Z'), $string); |
@@ -135,8 +128,7 @@ discard block |
||
| 135 | 128 | * @param mixed $str |
| 136 | 129 | * @return string |
| 137 | 130 | */ |
| 138 | - public function dbAddslashes($str = '') |
|
| 139 | - { |
|
| 131 | + public function dbAddslashes($str = '') { |
|
| 140 | 132 | if (!isset($str) || $str == '') { |
| 141 | 133 | return ''; |
| 142 | 134 | } |
@@ -148,8 +140,7 @@ discard block |
||
| 148 | 140 | * @param mixed $epoch |
| 149 | 141 | * @return bool|string |
| 150 | 142 | */ |
| 151 | - public function toTimestamp($epoch) |
|
| 152 | - { |
|
| 143 | + public function toTimestamp($epoch) { |
|
| 153 | 144 | return date('Y-m-d H:i:s', $epoch); |
| 154 | 145 | } |
| 155 | 146 | |
@@ -158,8 +149,7 @@ discard block |
||
| 158 | 149 | * @param mixed $timestamp |
| 159 | 150 | * @return bool|int|mixed |
| 160 | 151 | */ |
| 161 | - public function fromTimestamp($timestamp) |
|
| 162 | - { |
|
| 152 | + public function fromTimestamp($timestamp) { |
|
| 163 | 153 | if (preg_match('/([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})/', $timestamp, $parts)) { |
| 164 | 154 | $time = mktime($parts[4], $parts[5], $parts[6], $parts[2], $parts[3], $parts[1]); |
| 165 | 155 | } elseif (preg_match('/([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/', $timestamp, $parts)) { |
@@ -185,8 +175,7 @@ discard block |
||
| 185 | 175 | * @param string $file |
| 186 | 176 | * @return mixed |
| 187 | 177 | */ |
| 188 | - public function limitQuery($queryString, $numRows = '', $offset = 0, $line = '', $file = '') |
|
| 189 | - { |
|
| 178 | + public function limitQuery($queryString, $numRows = '', $offset = 0, $line = '', $file = '') { |
|
| 190 | 179 | if (!$numRows) { |
| 191 | 180 | $numRows = $this->maxMatches; |
| 192 | 181 | } |
@@ -213,8 +202,7 @@ discard block |
||
| 213 | 202 | * @param string $file optionally pass __FILE__ calling the query for logging |
| 214 | 203 | * @return mixed FALSE if no rows, if a single row it returns that, if multiple it returns an array of rows, associative responses only |
| 215 | 204 | */ |
| 216 | - public function qr($query, $line = '', $file = '') |
|
| 217 | - { |
|
| 205 | + public function qr($query, $line = '', $file = '') { |
|
| 218 | 206 | return $this->queryReturn($query, $line, $file); |
| 219 | 207 | } |
| 220 | 208 | |
@@ -225,8 +213,7 @@ discard block |
||
| 225 | 213 | * @param string $stripSlashes |
| 226 | 214 | * @return string |
| 227 | 215 | */ |
| 228 | - public function f($name, $stripSlashes = '') |
|
| 229 | - { |
|
| 216 | + public function f($name, $stripSlashes = '') { |
|
| 230 | 217 | if ($stripSlashes || ($this->autoStripslashes && !$stripSlashes)) { |
| 231 | 218 | return stripslashes($this->Record[$name]); |
| 232 | 219 | } else { |
@@ -242,8 +229,7 @@ discard block |
||
| 242 | 229 | * @param string $file |
| 243 | 230 | * @return void |
| 244 | 231 | */ |
| 245 | - public function halt($msg, $line = '', $file = '') |
|
| 246 | - { |
|
| 232 | + public function halt($msg, $line = '', $file = '') { |
|
| 247 | 233 | $this->unlock(false); |
| 248 | 234 | /* Just in case there is a table currently locked */ |
| 249 | 235 | |
@@ -271,8 +257,7 @@ discard block |
||
| 271 | 257 | * @param string $file |
| 272 | 258 | * @return mixed|void |
| 273 | 259 | */ |
| 274 | - public function logBackTrace($msg, $line = '', $file = '') |
|
| 275 | - { |
|
| 260 | + public function logBackTrace($msg, $line = '', $file = '') { |
|
| 276 | 261 | $backtrace = (function_exists('debug_backtrace') ? debug_backtrace() : []); |
| 277 | 262 | $this->log( |
| 278 | 263 | ('' !== getenv('REQUEST_URI') ? ' '.getenv('REQUEST_URI') : ''). |
@@ -303,8 +288,7 @@ discard block |
||
| 303 | 288 | } |
| 304 | 289 | } |
| 305 | 290 | |
| 306 | - public function emailError($queryString, $error, $line, $file) |
|
| 307 | - { |
|
| 291 | + public function emailError($queryString, $error, $line, $file) { |
|
| 308 | 292 | $subject = php_uname('n').' MySQLi Error'; |
| 309 | 293 | $smarty = new \TFSmarty(); |
| 310 | 294 | $smarty->assign([ |
@@ -331,8 +315,7 @@ discard block |
||
| 331 | 315 | * @param string $file |
| 332 | 316 | * @return mixed|void |
| 333 | 317 | */ |
| 334 | - public function haltmsg($msg, $line = '', $file = '') |
|
| 335 | - { |
|
| 318 | + public function haltmsg($msg, $line = '', $file = '') { |
|
| 336 | 319 | $this->log("Database error: $msg", $line, $file, 'error'); |
| 337 | 320 | if ($this->Errno != '0' || !in_array($this->Error, ['', '()'])) { |
| 338 | 321 | $sqlstate = mysqli_sqlstate($this->linkId); |
@@ -344,8 +327,7 @@ discard block |
||
| 344 | 327 | /** |
| 345 | 328 | * @return array |
| 346 | 329 | */ |
| 347 | - public function indexNames() |
|
| 348 | - { |
|
| 330 | + public function indexNames() { |
|
| 349 | 331 | return []; |
| 350 | 332 | } |
| 351 | 333 | |
@@ -357,8 +339,7 @@ discard block |
||
| 357 | 339 | * @param string|int $line Line Number |
| 358 | 340 | * @param string $file File Name |
| 359 | 341 | */ |
| 360 | - public function addLog($statement, $time, $line = '', $file = '') |
|
| 361 | - { |
|
| 342 | + public function addLog($statement, $time, $line = '', $file = '') { |
|
| 362 | 343 | $query = [ |
| 363 | 344 | 'statement' => $statement, |
| 364 | 345 | 'time' => $time * 1000 |
@@ -380,8 +361,7 @@ discard block |
||
| 380 | 361 | * Return logged queries. |
| 381 | 362 | * @return array Logged queries |
| 382 | 363 | */ |
| 383 | - public function getLog() |
|
| 384 | - { |
|
| 364 | + public function getLog() { |
|
| 385 | 365 | return $this->log; |
| 386 | 366 | } |
| 387 | 367 | } |
@@ -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 = '') |
|
| 61 | - { |
|
| 57 | + public function connect($database = '', $host = '', $user = '', $password = '') { |
|
| 62 | 58 | /* Handle defaults */ |
| 63 | 59 | if ($database == '') { |
| 64 | 60 | $database = $this->database; |
@@ -98,8 +94,7 @@ discard block |
||
| 98 | 94 | * Db::disconnect() |
| 99 | 95 | * @return bool |
| 100 | 96 | */ |
| 101 | - public function disconnect() |
|
| 102 | - { |
|
| 97 | + public function disconnect() { |
|
| 103 | 98 | $return = method_exists($this->linkId, 'close') ? $this->linkId->close() : false; |
| 104 | 99 | $this->linkId = 0; |
| 105 | 100 | return $return; |
@@ -109,8 +104,7 @@ discard block |
||
| 109 | 104 | * @param $string |
| 110 | 105 | * @return string |
| 111 | 106 | */ |
| 112 | - public function real_escape($string = '') |
|
| 113 | - { |
|
| 107 | + public function real_escape($string = '') { |
|
| 114 | 108 | if ((!is_resource($this->linkId) || $this->linkId == 0) && !$this->connect()) { |
| 115 | 109 | return $this->escape($string); |
| 116 | 110 | } |
@@ -121,8 +115,7 @@ discard block |
||
| 121 | 115 | * discard the query result |
| 122 | 116 | * @return void |
| 123 | 117 | */ |
| 124 | - public function free() |
|
| 125 | - { |
|
| 118 | + public function free() { |
|
| 126 | 119 | if (is_resource($this->queryId)) { |
| 127 | 120 | @mysqli_free_result($this->queryId); |
| 128 | 121 | } |
@@ -140,8 +133,7 @@ discard block |
||
| 140 | 133 | * @param string $file optionally pass __FILE__ calling the query for logging |
| 141 | 134 | * @return mixed FALSE if no rows, if a single row it returns that, if multiple it returns an array of rows, associative responses only |
| 142 | 135 | */ |
| 143 | - public function queryReturn($query, $line = '', $file = '') |
|
| 144 | - { |
|
| 136 | + public function queryReturn($query, $line = '', $file = '') { |
|
| 145 | 137 | $this->query($query, $line, $file); |
| 146 | 138 | if ($this->num_rows() == 0) { |
| 147 | 139 | return false; |
@@ -167,8 +159,7 @@ discard block |
||
| 167 | 159 | * @param string $file optionally pass __FILE__ calling the query for logging |
| 168 | 160 | * @return mixed FALSE if no rows, if a single row it returns that, if multiple it returns an array of rows, associative responses only |
| 169 | 161 | */ |
| 170 | - public function qr($query, $line = '', $file = '') |
|
| 171 | - { |
|
| 162 | + public function qr($query, $line = '', $file = '') { |
|
| 172 | 163 | return $this->queryReturn($query, $line, $file); |
| 173 | 164 | } |
| 174 | 165 | |
@@ -178,8 +169,7 @@ discard block |
||
| 178 | 169 | * @param string $query sql query like INSERT INTO table (col) VALUES (?) or SELECT * from table WHERE col1 = ? and col2 = ? or UPDATE table SET col1 = ?, col2 = ? WHERE col3 = ? |
| 179 | 170 | * @return int|\MyDb\Mysqli\mysqli_stmt |
| 180 | 171 | */ |
| 181 | - public function prepare($query) |
|
| 182 | - { |
|
| 172 | + public function prepare($query) { |
|
| 183 | 173 | if (!$this->connect()) { |
| 184 | 174 | return 0; |
| 185 | 175 | } |
@@ -198,8 +188,7 @@ discard block |
||
| 198 | 188 | * @param string $file |
| 199 | 189 | * @return mixed 0 if no query or query id handler, safe to ignore this return |
| 200 | 190 | */ |
| 201 | - public function query($queryString, $line = '', $file = '') |
|
| 202 | - { |
|
| 191 | + public function query($queryString, $line = '', $file = '') { |
|
| 203 | 192 | /* No empty queries, please, since PHP4 chokes on them. */ |
| 204 | 193 | /* The empty query string is passed on from the constructor, |
| 205 | 194 | * when calling the class without a query, e.g. in situations |
@@ -255,8 +244,7 @@ discard block |
||
| 255 | 244 | /** |
| 256 | 245 | * @return array|null|object |
| 257 | 246 | */ |
| 258 | - public function fetchObject() |
|
| 259 | - { |
|
| 247 | + public function fetchObject() { |
|
| 260 | 248 | $this->Record = @mysqli_fetch_object($this->queryId); |
| 261 | 249 | return $this->Record; |
| 262 | 250 | } |
@@ -269,8 +257,7 @@ discard block |
||
| 269 | 257 | * @param mixed $resultType |
| 270 | 258 | * @return bool |
| 271 | 259 | */ |
| 272 | - public function next_record($resultType = MYSQLI_BOTH) |
|
| 273 | - { |
|
| 260 | + public function next_record($resultType = MYSQLI_BOTH) { |
|
| 274 | 261 | if ($this->queryId === false) { |
| 275 | 262 | $this->haltmsg('next_record called with no query pending.'); |
| 276 | 263 | return 0; |
@@ -294,8 +281,7 @@ discard block |
||
| 294 | 281 | * @param integer $pos the row numbe starting at 0 to switch to |
| 295 | 282 | * @return bool whetherit was successfu or not. |
| 296 | 283 | */ |
| 297 | - public function seek($pos = 0) |
|
| 298 | - { |
|
| 284 | + public function seek($pos = 0) { |
|
| 299 | 285 | $status = @mysqli_data_seek($this->queryId, $pos); |
| 300 | 286 | if ($status) { |
| 301 | 287 | $this->Row = $pos; |
@@ -315,8 +301,7 @@ discard block |
||
| 315 | 301 | * |
| 316 | 302 | * @return bool |
| 317 | 303 | */ |
| 318 | - public function transactionBegin() |
|
| 319 | - { |
|
| 304 | + public function transactionBegin() { |
|
| 320 | 305 | if (version_compare(PHP_VERSION, '5.5.0') < 0) { |
| 321 | 306 | return true; |
| 322 | 307 | } |
@@ -331,8 +316,7 @@ discard block |
||
| 331 | 316 | * |
| 332 | 317 | * @return bool |
| 333 | 318 | */ |
| 334 | - public function transactionCommit() |
|
| 335 | - { |
|
| 319 | + public function transactionCommit() { |
|
| 336 | 320 | if (version_compare(PHP_VERSION, '5.5.0') < 0 || $this->linkId === 0) { |
| 337 | 321 | return true; |
| 338 | 322 | } |
@@ -344,8 +328,7 @@ discard block |
||
| 344 | 328 | * |
| 345 | 329 | * @return bool |
| 346 | 330 | */ |
| 347 | - public function transactionAbort() |
|
| 348 | - { |
|
| 331 | + public function transactionAbort() { |
|
| 349 | 332 | if (version_compare(PHP_VERSION, '5.5.0') < 0 || $this->linkId === 0) { |
| 350 | 333 | return true; |
| 351 | 334 | } |
@@ -361,8 +344,7 @@ discard block |
||
| 361 | 344 | * @param string $field |
| 362 | 345 | * @return int|string |
| 363 | 346 | */ |
| 364 | - public function getLastInsertId($table, $field) |
|
| 365 | - { |
|
| 347 | + public function getLastInsertId($table, $field) { |
|
| 366 | 348 | if (!isset($table) || $table == '' || !isset($field) || $field == '') { |
| 367 | 349 | return -1; |
| 368 | 350 | } |
@@ -378,8 +360,7 @@ discard block |
||
| 378 | 360 | * @param string $mode |
| 379 | 361 | * @return bool|int|\mysqli_result |
| 380 | 362 | */ |
| 381 | - public function lock($table, $mode = 'write') |
|
| 382 | - { |
|
| 363 | + public function lock($table, $mode = 'write') { |
|
| 383 | 364 | $this->connect(); |
| 384 | 365 | $query = 'lock tables '; |
| 385 | 366 | if (is_array($table)) { |
@@ -407,8 +388,7 @@ discard block |
||
| 407 | 388 | * @param bool $haltOnError optional, defaults to TRUE, whether or not to halt on error |
| 408 | 389 | * @return bool|int|\mysqli_result |
| 409 | 390 | */ |
| 410 | - public function unlock($haltOnError = true) |
|
| 411 | - { |
|
| 391 | + public function unlock($haltOnError = true) { |
|
| 412 | 392 | $this->connect(); |
| 413 | 393 | |
| 414 | 394 | $res = @mysqli_query($this->linkId, 'unlock tables'); |
@@ -425,8 +405,7 @@ discard block |
||
| 425 | 405 | * Db::affectedRows() |
| 426 | 406 | * @return int |
| 427 | 407 | */ |
| 428 | - public function affectedRows() |
|
| 429 | - { |
|
| 408 | + public function affectedRows() { |
|
| 430 | 409 | return @mysqli_affected_rows($this->linkId); |
| 431 | 410 | } |
| 432 | 411 | |
@@ -434,8 +413,7 @@ discard block |
||
| 434 | 413 | * Db::num_rows() |
| 435 | 414 | * @return int |
| 436 | 415 | */ |
| 437 | - public function num_rows() |
|
| 438 | - { |
|
| 416 | + public function num_rows() { |
|
| 439 | 417 | return @mysqli_num_rows($this->queryId); |
| 440 | 418 | } |
| 441 | 419 | |
@@ -443,8 +421,7 @@ discard block |
||
| 443 | 421 | * Db::num_fields() |
| 444 | 422 | * @return int |
| 445 | 423 | */ |
| 446 | - public function num_fields() |
|
| 447 | - { |
|
| 424 | + public function num_fields() { |
|
| 448 | 425 | return @mysqli_num_fields($this->queryId); |
| 449 | 426 | } |
| 450 | 427 | |
@@ -453,8 +430,7 @@ discard block |
||
| 453 | 430 | * |
| 454 | 431 | * @return array |
| 455 | 432 | */ |
| 456 | - public function tableNames() |
|
| 457 | - { |
|
| 433 | + public function tableNames() { |
|
| 458 | 434 | $return = []; |
| 459 | 435 | $this->query('SHOW TABLES'); |
| 460 | 436 | $i = 0; |