Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like DB often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use DB, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 16 | final class DB |
||
| 17 | { |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @var int |
||
| 21 | */ |
||
| 22 | public $query_count = 0; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @var \mysqli |
||
| 26 | */ |
||
| 27 | private $link = false; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @var bool |
||
| 31 | */ |
||
| 32 | private $connected = false; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @var array |
||
| 36 | */ |
||
| 37 | private $mysqlDefaultTimeFunctions; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @var string |
||
| 41 | */ |
||
| 42 | private $hostname = ''; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @var string |
||
| 46 | */ |
||
| 47 | private $username = ''; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @var string |
||
| 51 | */ |
||
| 52 | private $password = ''; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @var string |
||
| 56 | */ |
||
| 57 | private $database = ''; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @var int |
||
| 61 | */ |
||
| 62 | private $port = 3306; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @var string |
||
| 66 | */ |
||
| 67 | private $charset = 'utf8'; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @var string |
||
| 71 | */ |
||
| 72 | private $socket = ''; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @var bool |
||
| 76 | */ |
||
| 77 | private $session_to_db = false; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @var bool |
||
| 81 | */ |
||
| 82 | private $_in_transaction = false; |
||
| 83 | |||
| 84 | /** |
||
| 85 | * @var bool |
||
| 86 | */ |
||
| 87 | private $_convert_null_to_empty_string = false; |
||
| 88 | |||
| 89 | /** |
||
| 90 | * @var Debug |
||
| 91 | */ |
||
| 92 | private $_debug; |
||
| 93 | |||
| 94 | /** |
||
| 95 | * __construct() |
||
| 96 | * |
||
| 97 | * @param string $hostname |
||
| 98 | * @param string $username |
||
| 99 | * @param string $password |
||
| 100 | * @param string $database |
||
| 101 | * @param int $port |
||
| 102 | * @param string $charset |
||
| 103 | * @param boolean|string $exit_on_error use a empty string "" or false to disable it |
||
| 104 | * @param boolean|string $echo_on_error use a empty string "" or false to disable it |
||
| 105 | * @param string $logger_class_name |
||
| 106 | * @param string $logger_level 'TRACE', 'DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL' |
||
| 107 | * @param boolean|string $session_to_db use a empty string "" or false to disable it |
||
| 108 | */ |
||
| 109 | 10 | protected function __construct($hostname, $username, $password, $database, $port, $charset, $exit_on_error, $echo_on_error, $logger_class_name, $logger_level, $session_to_db) |
|
| 160 | |||
| 161 | /** |
||
| 162 | * Prevent the instance from being cloned. |
||
| 163 | * |
||
| 164 | * @return void |
||
| 165 | */ |
||
| 166 | private function __clone() |
||
| 169 | |||
| 170 | /** |
||
| 171 | * __destruct |
||
| 172 | * |
||
| 173 | */ |
||
| 174 | public function __destruct() |
||
| 181 | 10 | ||
| 182 | 10 | /** |
|
| 183 | 10 | * __wakeup |
|
| 184 | * |
||
| 185 | 10 | * @return void |
|
| 186 | 4 | */ |
|
| 187 | 4 | public function __wakeup() |
|
| 191 | 4 | ||
| 192 | /** |
||
| 193 | * Load the config from the constructor. |
||
| 194 | 7 | * |
|
| 195 | * @param string $hostname |
||
| 196 | * @param string $username |
||
| 197 | * @param string $password |
||
| 198 | 10 | * @param string $database |
|
| 199 | * @param int $port |
||
| 200 | * @param string $charset |
||
| 201 | * @param boolean|string $exit_on_error <p>Use a empty string "" or false to disable it.</p> |
||
| 202 | 10 | * @param boolean|string $echo_on_error <p>Use a empty string "" or false to disable it.</p> |
|
| 203 | * @param string $logger_class_name |
||
| 204 | 10 | * @param string $logger_level |
|
| 205 | 10 | * @param boolean|string $session_to_db <p>Use a empty string "" or false to disable it.</p> |
|
| 206 | * |
||
| 207 | 10 | * @return bool |
|
| 208 | 10 | */ |
|
| 209 | 10 | private function _loadConfig($hostname, $username, $password, $database, $port, $charset, $exit_on_error, $echo_on_error, $logger_class_name, $logger_level, $session_to_db) |
|
| 253 | |||
| 254 | /** |
||
| 255 | * Parses arrays with value pairs and generates SQL to use in queries. |
||
| 256 | 7 | * |
|
| 257 | * @param array $arrayPair |
||
| 258 | * @param string $glue <p>This is the separator.</p> |
||
| 259 | * |
||
| 260 | * @return string |
||
| 261 | * |
||
| 262 | * @internal |
||
| 263 | */ |
||
| 264 | public function _parseArrayPair($arrayPair, $glue = ',') |
||
| 410 | 10 | ||
| 411 | 10 | /** |
|
| 412 | 10 | * _parseQueryParams |
|
| 413 | 10 | * |
|
| 414 | 10 | * @param string $sql |
|
| 415 | 10 | * @param array $params |
|
| 416 | 10 | * |
|
| 417 | 10 | * @return string |
|
| 418 | 10 | */ |
|
| 419 | private function _parseQueryParams($sql, array $params) |
||
| 440 | |||
| 441 | /** |
||
| 442 | * Gets the number of affected rows in a previous MySQL operation. |
||
| 443 | * |
||
| 444 | * @return int |
||
| 445 | */ |
||
| 446 | public function affected_rows() |
||
| 450 | 35 | ||
| 451 | /** |
||
| 452 | 35 | * Begins a transaction, by turning off auto commit. |
|
| 453 | * |
||
| 454 | * @return bool <p>This will return true or false indicating success of transaction</p> |
||
| 455 | */ |
||
| 456 | 35 | public function beginTransaction() |
|
| 477 | |||
| 478 | 33 | /** |
|
| 479 | 33 | * Clear the errors in "_debug->_errors". |
|
| 480 | 28 | * |
|
| 481 | 28 | * @return bool |
|
| 482 | 24 | */ |
|
| 483 | public function clearErrors() |
||
| 487 | |||
| 488 | 27 | /** |
|
| 489 | * Closes a previously opened database connection. |
||
| 490 | */ |
||
| 491 | 27 | public function close() |
|
| 499 | 22 | ||
| 500 | 22 | /** |
|
| 501 | * Open a new connection to the MySQL server. |
||
| 502 | 22 | * |
|
| 503 | * @return bool |
||
| 504 | * |
||
| 505 | * @throws DBConnectException |
||
| 506 | 8 | */ |
|
| 507 | 8 | public function connect() |
|
| 549 | 3 | ||
| 550 | 3 | /** |
|
| 551 | * Execute a "delete"-query. |
||
| 552 | 3 | * |
|
| 553 | * @param string $table |
||
| 554 | * @param string|array $where |
||
| 555 | * @param string|null $databaseName <p>Use <strong>null</strong> if you will use the current database.</p> |
||
| 556 | * |
||
| 557 | * @return false|int <p>false on error</p> |
||
| 558 | * |
||
| 559 | * * @throws QueryException |
||
| 560 | */ |
||
| 561 | View Code Duplication | public function delete($table, $where, $databaseName = null) |
|
| 588 | |||
| 589 | /** |
||
| 590 | * Ends a transaction and commits if no errors, then ends autocommit. |
||
| 591 | * |
||
| 592 | * @return bool <p>This will return true or false indicating success of transactions.</p> |
||
| 593 | */ |
||
| 594 | public function endTransaction() |
||
| 610 | |||
| 611 | 26 | /** |
|
| 612 | 22 | * Get all errors from "$this->_errors". |
|
| 613 | 22 | * |
|
| 614 | * @return array|false <p>false === on errors</p> |
||
| 615 | 26 | */ |
|
| 616 | public function errors() |
||
| 622 | |||
| 623 | /** |
||
| 624 | * Escape: Use "mysqli_real_escape_string" and clean non UTF-8 chars + some extra optional stuff. |
||
| 625 | * |
||
| 626 | * @param mixed $var boolean: convert into "integer"<br /> |
||
| 627 | * int: int (don't change it)<br /> |
||
| 628 | * float: float (don't change it)<br /> |
||
| 629 | * null: null (don't change it)<br /> |
||
| 630 | * array: run escape() for every key => value<br /> |
||
| 631 | * string: run UTF8::cleanup() and mysqli_real_escape_string()<br /> |
||
| 632 | * @param bool $stripe_non_utf8 |
||
| 633 | * @param bool $html_entity_decode |
||
| 634 | * @param bool|null $convert_array <strong>false</strong> => Keep the array.<br /> |
||
| 635 | * <strong>true</strong> => Convert to string var1,var2,var3...<br /> |
||
| 636 | * <strong>null</strong> => Convert the array into null, every time. |
||
| 637 | * |
||
| 638 | * @return mixed |
||
| 639 | */ |
||
| 640 | public function escape($var = '', $stripe_non_utf8 = true, $html_entity_decode = false, $convert_array = false) |
||
| 754 | |||
| 755 | /** |
||
| 756 | * Execute select/insert/update/delete sql-queries. |
||
| 757 | * |
||
| 758 | * @param string $query sql-query |
||
| 759 | * @param bool $useCache use cache? |
||
| 760 | * @param int $cacheTTL cache-ttl in seconds |
||
| 761 | 35 | * |
|
| 762 | * @return mixed "array" by "<b>SELECT</b>"-queries<br /> |
||
| 763 | 35 | * "int" (insert_id) by "<b>INSERT</b>"-queries<br /> |
|
| 764 | * "int" (affected_rows) by "<b>UPDATE / DELETE</b>"-queries<br /> |
||
| 765 | * "true" by e.g. "DROP"-queries<br /> |
||
| 766 | * "false" on error |
||
| 767 | * |
||
| 768 | * @throws QueryException |
||
| 769 | */ |
||
| 770 | public static function execSQL($query, $useCache = false, $cacheTTL = 3600) |
||
| 817 | |||
| 818 | /** |
||
| 819 | 8 | * Get all table-names via "SHOW TABLES". |
|
| 820 | * |
||
| 821 | * @return array |
||
| 822 | 8 | */ |
|
| 823 | public function getAllTables() |
||
| 830 | |||
| 831 | /** |
||
| 832 | * @return Debug |
||
| 833 | */ |
||
| 834 | 3 | public function getDebugger() |
|
| 838 | 3 | ||
| 839 | 2 | /** |
|
| 840 | 2 | * Get errors from "$this->_errors". |
|
| 841 | * |
||
| 842 | 3 | * @return array |
|
| 843 | 3 | */ |
|
| 844 | 3 | public function getErrors() |
|
| 848 | |||
| 849 | /** |
||
| 850 | * getInstance() |
||
| 851 | * |
||
| 852 | * @param string $hostname |
||
| 853 | * @param string $username |
||
| 854 | * @param string $password |
||
| 855 | * @param string $database |
||
| 856 | 3 | * @param string $port default is (int)3306 |
|
| 857 | * @param string $charset default is 'utf8' or 'utf8mb4' (if supported) |
||
| 858 | * @param bool|string $exit_on_error use a empty string "" or false to disable it |
||
| 859 | 3 | * @param bool|string $echo_on_error use a empty string "" or false to disable it |
|
| 860 | 3 | * @param string $logger_class_name |
|
| 861 | 3 | * @param string $logger_level |
|
| 862 | 3 | * @param bool|string $session_to_db use a empty string "" or false to disable it |
|
| 863 | * |
||
| 864 | * @return \voku\db\DB |
||
| 865 | 3 | */ |
|
| 866 | public static function getInstance($hostname = '', $username = '', $password = '', $database = '', $port = '', $charset = '', $exit_on_error = '', $echo_on_error = '', $logger_class_name = '', $logger_level = '', $session_to_db = '') |
||
| 912 | 1 | ||
| 913 | /** |
||
| 914 | * Get the mysqli-link (link identifier returned by mysqli-connect). |
||
| 915 | * |
||
| 916 | * @return \mysqli |
||
| 917 | 1 | */ |
|
| 918 | public function getLink() |
||
| 922 | 1 | ||
| 923 | 1 | /** |
|
| 924 | 1 | * Get the current charset. |
|
| 925 | 1 | * |
|
| 926 | * @return string |
||
| 927 | 1 | */ |
|
| 928 | 2 | public function get_charset() |
|
| 932 | |||
| 933 | /** |
||
| 934 | * Check if we are in a transaction. |
||
| 935 | * |
||
| 936 | * @return bool |
||
| 937 | */ |
||
| 938 | public function inTransaction() |
||
| 942 | |||
| 943 | /** |
||
| 944 | * Execute a "insert"-query. |
||
| 945 | * |
||
| 946 | * @param string $table |
||
| 947 | * @param array $data |
||
| 948 | * @param string|null $databaseName <p>Use <strong>null</strong> if you will use the current database.</p> |
||
| 949 | * |
||
| 950 | * @return false|int <p>false on error</p> |
||
| 951 | * |
||
| 952 | * @throws QueryException |
||
| 953 | */ |
||
| 954 | public function insert($table, array $data = array(), $databaseName = null) |
||
| 981 | |||
| 982 | /** |
||
| 983 | * Returns the auto generated id used in the last query. |
||
| 984 | * |
||
| 985 | * @return int|string |
||
| 986 | */ |
||
| 987 | public function insert_id() |
||
| 991 | |||
| 992 | /** |
||
| 993 | * Check if db-connection is ready. |
||
| 994 | * |
||
| 995 | * @return boolean |
||
| 996 | 7 | */ |
|
| 997 | public function isReady() |
||
| 1001 | 5 | ||
| 1002 | 7 | /** |
|
| 1003 | 5 | * Get the last sql-error. |
|
| 1004 | 5 | * |
|
| 1005 | * @return string|false <p>false === there was no error</p> |
||
| 1006 | 7 | */ |
|
| 1007 | public function lastError() |
||
| 1013 | |||
| 1014 | 7 | /** |
|
| 1015 | * Execute a sql-multi-query. |
||
| 1016 | 7 | * |
|
| 1017 | * @param string $sql |
||
| 1018 | * |
||
| 1019 | * @return false|Result[] "Result"-Array by "<b>SELECT</b>"-queries<br /> |
||
| 1020 | * "boolean" by only "<b>INSERT</b>"-queries<br /> |
||
| 1021 | * "boolean" by only (affected_rows) by "<b>UPDATE / DELETE</b>"-queries<br /> |
||
| 1022 | * "boolean" by only by e.g. "DROP"-queries<br /> |
||
| 1023 | * |
||
| 1024 | * @throws QueryException |
||
| 1025 | */ |
||
| 1026 | 1 | public function multi_query($sql) |
|
| 1088 | 1 | ||
| 1089 | 1 | /** |
|
| 1090 | * Pings a server connection, or tries to reconnect |
||
| 1091 | * if the connection has gone down. |
||
| 1092 | * |
||
| 1093 | 1 | * @return boolean |
|
| 1094 | */ |
||
| 1095 | 1 | public function ping() |
|
| 1109 | 1 | ||
| 1110 | /** |
||
| 1111 | * Get a new "Prepare"-Object for your sql-query. |
||
| 1112 | 1 | * |
|
| 1113 | 1 | * @param string $query |
|
| 1114 | * |
||
| 1115 | * @return Prepare |
||
| 1116 | */ |
||
| 1117 | public function prepare($query) |
||
| 1121 | |||
| 1122 | 1 | /** |
|
| 1123 | * Execute a sql-query and return the result-array for select-statements. |
||
| 1124 | 1 | * |
|
| 1125 | 1 | * @param $query |
|
| 1126 | * |
||
| 1127 | * @return mixed |
||
| 1128 | * @deprecated |
||
| 1129 | * @throws \Exception |
||
| 1130 | */ |
||
| 1131 | public static function qry($query) |
||
| 1156 | |||
| 1157 | /** |
||
| 1158 | * Execute a sql-query. |
||
| 1159 | 4 | * |
|
| 1160 | * @param string $sql <p>The sql query-string.</p> |
||
| 1161 | 4 | * |
|
| 1162 | * @param array|boolean $params <p> |
||
| 1163 | * "array" of sql-query-parameters<br/> |
||
| 1164 | * "false" if you don't need any parameter (default)<br/> |
||
| 1165 | * </p> |
||
| 1166 | * |
||
| 1167 | * @return bool|int|Result <p> |
||
| 1168 | * "Result" by "<b>SELECT</b>"-queries<br /> |
||
| 1169 | 4 | * "int" (insert_id) by "<b>INSERT / REPLACE</b>"-queries<br /> |
|
| 1170 | * "int" (affected_rows) by "<b>UPDATE / DELETE</b>"-queries<br /> |
||
| 1171 | 4 | * "true" by e.g. "DROP"-queries<br /> |
|
| 1172 | * "false" on error |
||
| 1173 | * </p> |
||
| 1174 | * |
||
| 1175 | * @throws QueryException |
||
| 1176 | */ |
||
| 1177 | public function query($sql = '', $params = false) |
||
| 1251 | |||
| 1252 | /** |
||
| 1253 | 18 | * Error-handling for the sql-query. |
|
| 1254 | * |
||
| 1255 | 18 | * @param string $errorMsg |
|
| 1256 | * @param string $sql |
||
| 1257 | * @param array|bool $sqlParams false if there wasn't any parameter |
||
| 1258 | * |
||
| 1259 | 18 | * @throws QueryException |
|
| 1260 | * @throws DBGoneAwayException |
||
| 1261 | 18 | * |
|
| 1262 | * @return bool |
||
| 1263 | */ |
||
| 1264 | View Code Duplication | protected function queryErrorHandling($errorMsg, $sql, $sqlParams = false) |
|
| 1292 | 2 | ||
| 1293 | /** |
||
| 1294 | 23 | * Quote && Escape e.g. a table name string. |
|
| 1295 | 1 | * |
|
| 1296 | 1 | * @param string $str |
|
| 1297 | * |
||
| 1298 | 23 | * @return string |
|
| 1299 | 1 | */ |
|
| 1300 | 1 | public function quote_string($str) |
|
| 1313 | |||
| 1314 | 23 | /** |
|
| 1315 | 1 | * Reconnect to the MySQL-Server. |
|
| 1316 | 1 | * |
|
| 1317 | * @param bool $checkViaPing |
||
| 1318 | 23 | * |
|
| 1319 | 2 | * @return bool |
|
| 1320 | 2 | */ |
|
| 1321 | public function reconnect($checkViaPing = false) |
||
| 1336 | 4 | ||
| 1337 | /** |
||
| 1338 | 23 | * Execute a "replace"-query. |
|
| 1339 | 1 | * |
|
| 1340 | 1 | * @param string $table |
|
| 1341 | * @param array $data |
||
| 1342 | 23 | * @param null|string $databaseName <p>Use <strong>null</strong> if you will use the current database.</p> |
|
| 1343 | 1 | * |
|
| 1344 | 1 | * @return false|int <p>false on error</p> |
|
| 1345 | * |
||
| 1346 | 23 | * @throws QueryException |
|
| 1347 | 2 | */ |
|
| 1348 | 2 | public function replace($table, array $data = array(), $databaseName = null) |
|
| 1389 | |||
| 1390 | 23 | /** |
|
| 1391 | 23 | * Rollback in a transaction. |
|
| 1392 | */ |
||
| 1393 | 23 | public function rollback() |
|
| 1406 | |||
| 1407 | 23 | /** |
|
| 1408 | 23 | * Try to secure a variable, so can you use it in sql-queries. |
|
| 1409 | 23 | * |
|
| 1410 | * <p> |
||
| 1411 | 23 | * <strong>int:</strong> (also strings that contains only an int-value)<br /> |
|
| 1412 | 2 | * 1. parse into "int" |
|
| 1413 | 2 | * </p><br /> |
|
| 1414 | * |
||
| 1415 | 23 | * <p> |
|
| 1416 | 23 | * <strong>float:</strong><br /> |
|
| 1417 | * 1. return "float" |
||
| 1418 | 23 | * </p><br /> |
|
| 1419 | * |
||
| 1420 | * <p> |
||
| 1421 | * <strong>string:</strong><br /> |
||
| 1422 | * 1. check if the string isn't a default mysql-time-function e.g. 'CURDATE()'<br /> |
||
| 1423 | * 2. trim whitespace<br /> |
||
| 1424 | * 3. trim '<br /> |
||
| 1425 | * 4. escape the string (and remove non utf-8 chars)<br /> |
||
| 1426 | * 5. trim ' again (because we maybe removed some chars)<br /> |
||
| 1427 | * 6. add ' around the new string<br /> |
||
| 1428 | 26 | * </p><br /> |
|
| 1429 | * |
||
| 1430 | 26 | * <p> |
|
| 1431 | 26 | * <strong>array:</strong><br /> |
|
| 1432 | 26 | * 1. return null |
|
| 1433 | 26 | * </p><br /> |
|
| 1434 | 26 | * |
|
| 1435 | * <p> |
||
| 1436 | 26 | * <strong>object:</strong><br /> |
|
| 1437 | 26 | * 1. return false |
|
| 1438 | * </p><br /> |
||
| 1439 | 26 | * |
|
| 1440 | * <p> |
||
| 1441 | * <strong>null:</strong><br /> |
||
| 1442 | * 1. return null |
||
| 1443 | * </p> |
||
| 1444 | * |
||
| 1445 | * @param mixed $var |
||
| 1446 | * |
||
| 1447 | 1 | * @return mixed |
|
| 1448 | */ |
||
| 1449 | 1 | public function secure($var) |
|
| 1475 | 1 | ||
| 1476 | /** |
||
| 1477 | 1 | * Execute a "select"-query. |
|
| 1478 | * |
||
| 1479 | * @param string $table |
||
| 1480 | * @param string|array $where |
||
| 1481 | 1 | * @param string|null $databaseName <p>Use <strong>null</strong> if you will use the current database.</p> |
|
| 1482 | 1 | * |
|
| 1483 | * @return false|Result <p>false on error</p> |
||
| 1484 | 1 | * |
|
| 1485 | 1 | * @throws QueryException |
|
| 1486 | */ |
||
| 1487 | 1 | View Code Duplication | public function select($table, $where = '1=1', $databaseName = null) |
| 1514 | |||
| 1515 | /** |
||
| 1516 | * Set the current charset. |
||
| 1517 | 6 | * |
|
| 1518 | * @param string $charset |
||
| 1519 | * |
||
| 1520 | 6 | * @return bool |
|
| 1521 | */ |
||
| 1522 | 6 | public function set_charset($charset) |
|
| 1544 | 6 | ||
| 1545 | /** |
||
| 1546 | * Set the option to convert null to "''" (empty string). |
||
| 1547 | * |
||
| 1548 | 6 | * Used in secure() => select(), insert(), update(), delete() |
|
| 1549 | * |
||
| 1550 | 6 | * @param $bool |
|
| 1551 | */ |
||
| 1552 | public function set_convert_null_to_empty_string($bool) |
||
| 1556 | |||
| 1557 | /** |
||
| 1558 | * Enables or disables internal report functions |
||
| 1559 | * |
||
| 1560 | * @link http://php.net/manual/en/function.mysqli-report.php |
||
| 1561 | * |
||
| 1562 | * @param int $flags <p> |
||
| 1563 | * <table> |
||
| 1564 | 2 | * Supported flags |
|
| 1565 | * <tr valign="top"> |
||
| 1566 | * <td>Name</td> |
||
| 1567 | 2 | * <td>Description</td> |
|
| 1568 | * </tr> |
||
| 1569 | 2 | * <tr valign="top"> |
|
| 1570 | 1 | * <td><b>MYSQLI_REPORT_OFF</b></td> |
|
| 1571 | * <td>Turns reporting off</td> |
||
| 1572 | 1 | * </tr> |
|
| 1573 | * <tr valign="top"> |
||
| 1574 | * <td><b>MYSQLI_REPORT_ERROR</b></td> |
||
| 1575 | 2 | * <td>Report errors from mysqli function calls</td> |
|
| 1576 | 1 | * </tr> |
|
| 1577 | 2 | * <tr valign="top"> |
|
| 1578 | 2 | * <td><b>MYSQLI_REPORT_STRICT</b></td> |
|
| 1579 | 2 | * <td> |
|
| 1580 | 1 | * Throw <b>mysqli_sql_exception</b> for errors |
|
| 1581 | * instead of warnings |
||
| 1582 | * </td> |
||
| 1583 | 2 | * </tr> |
|
| 1584 | * <tr valign="top"> |
||
| 1585 | * <td><b>MYSQLI_REPORT_INDEX</b></td> |
||
| 1586 | * <td>Report if no index or bad index was used in a query</td> |
||
| 1587 | 2 | * </tr> |
|
| 1588 | * <tr valign="top"> |
||
| 1589 | 2 | * <td><b>MYSQLI_REPORT_ALL</b></td> |
|
| 1590 | * <td>Set all options (report all)</td> |
||
| 1591 | * </tr> |
||
| 1592 | * </table> |
||
| 1593 | * </p> |
||
| 1594 | * |
||
| 1595 | * @return bool |
||
| 1596 | */ |
||
| 1597 | public function set_mysqli_report($flags) |
||
| 1601 | |||
| 1602 | /** |
||
| 1603 | 20 | * Show config errors by throw exceptions. |
|
| 1604 | * |
||
| 1605 | * @return bool |
||
| 1606 | 20 | * |
|
| 1607 | * @throws \InvalidArgumentException |
||
| 1608 | 20 | */ |
|
| 1609 | 1 | public function showConfigError() |
|
| 1637 | |||
| 1638 | 1 | /** |
|
| 1639 | * alias: "beginTransaction()" |
||
| 1640 | 1 | */ |
|
| 1641 | public function startTransaction() |
||
| 1645 | |||
| 1646 | 9 | /** |
|
| 1647 | * Execute a "update"-query. |
||
| 1648 | 9 | * |
|
| 1649 | * @param string $table |
||
| 1650 | * @param array $data |
||
| 1651 | * @param array|string $where |
||
| 1652 | * @param null|string $databaseName <p>Use <strong>null</strong> if you will use the current database.</p> |
||
| 1653 | * |
||
| 1654 | * @return false|int <p>false on error</p> |
||
| 1655 | * |
||
| 1656 | * @throws QueryException |
||
| 1657 | */ |
||
| 1658 | public function update($table, array $data = array(), $where = '1=1', $databaseName = null) |
||
| 1693 | |||
| 1694 | } |
||
| 1695 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.