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 bool |
||
| 91 | */ |
||
| 92 | private $_ssl = false; |
||
| 93 | /** |
||
| 94 | * The path name to the key file |
||
| 95 | * |
||
| 96 | * @var string |
||
| 97 | */ |
||
| 98 | private $_clientkey; |
||
| 99 | /** |
||
| 100 | * The path name to the certificate file |
||
| 101 | * |
||
| 102 | * @var string |
||
| 103 | */ |
||
| 104 | private $_clientcert; |
||
| 105 | /** |
||
| 106 | * The path name to the certificate authority file |
||
| 107 | * |
||
| 108 | * @var string |
||
| 109 | 10 | */ |
|
| 110 | private $_cacert; |
||
| 111 | 10 | ||
| 112 | /** |
||
| 113 | 10 | * @var Debug |
|
| 114 | */ |
||
| 115 | 10 | private $_debug; |
|
| 116 | 10 | ||
| 117 | 10 | /** |
|
| 118 | 10 | * __construct() |
|
| 119 | 10 | * |
|
| 120 | 10 | * @param string $hostname |
|
| 121 | 10 | * @param string $username |
|
| 122 | 10 | * @param string $password |
|
| 123 | 10 | * @param string $database |
|
| 124 | 10 | * @param int $port |
|
| 125 | 10 | * @param string $charset |
|
| 126 | * @param boolean|string $exit_on_error use a empty string "" or false to disable it |
||
| 127 | 10 | * @param boolean|string $echo_on_error use a empty string "" or false to disable it |
|
| 128 | * @param string $logger_class_name |
||
| 129 | 7 | * @param string $logger_level 'TRACE', 'DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL' |
|
| 130 | * @param boolean|string $session_to_db use a empty string "" or false to disable it |
||
| 131 | 4 | */ |
|
| 132 | protected function __construct($hostname, $username, $password, $database, $port, $charset, $exit_on_error, $echo_on_error, $logger_class_name, $logger_level, $session_to_db) |
||
| 183 | 10 | ||
| 184 | /** |
||
| 185 | 10 | * Prevent the instance from being cloned. |
|
| 186 | 4 | * |
|
| 187 | 4 | * @return void |
|
| 188 | */ |
||
| 189 | 10 | private function __clone() |
|
| 192 | |||
| 193 | /** |
||
| 194 | 7 | * __destruct |
|
| 195 | * |
||
| 196 | */ |
||
| 197 | public function __destruct() |
||
| 204 | 10 | ||
| 205 | 10 | /** |
|
| 206 | * __wakeup |
||
| 207 | 10 | * |
|
| 208 | 10 | * @return void |
|
| 209 | 10 | */ |
|
| 210 | public function __wakeup() |
||
| 214 | |||
| 215 | 10 | /** |
|
| 216 | 10 | * Load the config from the constructor. |
|
| 217 | * |
||
| 218 | 10 | * @param string $hostname |
|
| 219 | * @param string $username |
||
| 220 | 10 | * @param string $password |
|
| 221 | * @param string $database |
||
| 222 | * @param int $port |
||
| 223 | * @param string $charset |
||
| 224 | * @param boolean|string $exit_on_error <p>Use a empty string "" or false to disable it.</p> |
||
| 225 | * @param boolean|string $echo_on_error <p>Use a empty string "" or false to disable it.</p> |
||
| 226 | * @param string $logger_class_name |
||
| 227 | * @param string $logger_level |
||
| 228 | * @param boolean|string $session_to_db <p>Use a empty string "" or false to disable it.</p> |
||
| 229 | * |
||
| 230 | 10 | * @return bool |
|
| 231 | */ |
||
| 232 | private function _loadConfig($hostname, $username, $password, $database, $port, $charset, $exit_on_error, $echo_on_error, $logger_class_name, $logger_level, $session_to_db) |
||
| 276 | 9 | ||
| 277 | 9 | /** |
|
| 278 | 9 | * Parses arrays with value pairs and generates SQL to use in queries. |
|
| 279 | * |
||
| 280 | * @param array $arrayPair |
||
| 281 | 9 | * @param string $glue <p>This is the separator.</p> |
|
| 282 | 9 | * |
|
| 283 | 9 | * @return string |
|
| 284 | 9 | * |
|
| 285 | 9 | * @internal |
|
| 286 | 9 | */ |
|
| 287 | 9 | public function _parseArrayPair($arrayPair, $glue = ',') |
|
| 433 | |||
| 434 | /** |
||
| 435 | * _parseQueryParams |
||
| 436 | * |
||
| 437 | * @param string $sql |
||
| 438 | * @param array $params |
||
| 439 | * |
||
| 440 | * @return string |
||
| 441 | */ |
||
| 442 | private function _parseQueryParams($sql, array $params) |
||
| 463 | |||
| 464 | 33 | /** |
|
| 465 | 3 | * Gets the number of affected rows in a previous MySQL operation. |
|
| 466 | 33 | * |
|
| 467 | 3 | * @return int |
|
| 468 | 33 | */ |
|
| 469 | 3 | public function affected_rows() |
|
| 473 | 33 | ||
| 474 | 33 | /** |
|
| 475 | * Begins a transaction, by turning off auto commit. |
||
| 476 | 33 | * |
|
| 477 | * @return bool <p>This will return true or false indicating success of transaction</p> |
||
| 478 | 33 | */ |
|
| 479 | 33 | public function beginTransaction() |
|
| 495 | 25 | ||
| 496 | |||
| 497 | /** |
||
| 498 | 23 | * Clear the errors in "_debug->_errors". |
|
| 499 | 22 | * |
|
| 500 | 22 | * @return bool |
|
| 501 | */ |
||
| 502 | 22 | public function clearErrors() |
|
| 506 | 8 | ||
| 507 | 8 | /** |
|
| 508 | 8 | * Closes a previously opened database connection. |
|
| 509 | * |
||
| 510 | 8 | * @return bool |
|
| 511 | */ |
||
| 512 | public function close() |
||
| 526 | |||
| 527 | /** |
||
| 528 | * Open a new connection to the MySQL server. |
||
| 529 | * |
||
| 530 | * @return bool |
||
| 531 | * |
||
| 532 | * @throws DBConnectException |
||
| 533 | 3 | */ |
|
| 534 | public function connect() |
||
| 605 | |||
| 606 | /** |
||
| 607 | 26 | * Execute a "delete"-query. |
|
| 608 | 1 | * |
|
| 609 | * @param string $table |
||
| 610 | * @param string|array $where |
||
| 611 | 26 | * @param string|null $databaseName <p>Use <strong>null</strong> if you will use the current database.</p> |
|
| 612 | 22 | * |
|
| 613 | 22 | * @return false|int <p>false on error</p> |
|
| 614 | * |
||
| 615 | 26 | * * @throws QueryException |
|
| 616 | */ |
||
| 617 | 26 | View Code Duplication | public function delete($table, $where, $databaseName = null) |
| 644 | 2 | ||
| 645 | /** |
||
| 646 | * Ends a transaction and commits if no errors, then ends autocommit. |
||
| 647 | 33 | * |
|
| 648 | 2 | * @return bool <p>This will return true or false indicating success of transactions.</p> |
|
| 649 | */ |
||
| 650 | public function endTransaction() |
||
| 666 | 33 | ||
| 667 | /** |
||
| 668 | 33 | * Get all errors from "$this->_errors". |
|
| 669 | 33 | * |
|
| 670 | * @return array|false <p>false === on errors</p> |
||
| 671 | */ |
||
| 672 | public function errors() |
||
| 678 | |||
| 679 | /** |
||
| 680 | 5 | * Escape: Use "mysqli_real_escape_string" and clean non UTF-8 chars + some extra optional stuff. |
|
| 681 | * |
||
| 682 | * @param mixed $var boolean: convert into "integer"<br /> |
||
| 683 | 33 | * int: int (don't change it)<br /> |
|
| 684 | * float: float (don't change it)<br /> |
||
| 685 | * null: null (don't change it)<br /> |
||
| 686 | * array: run escape() for every key => value<br /> |
||
| 687 | 3 | * string: run UTF8::cleanup() and mysqli_real_escape_string()<br /> |
|
| 688 | 3 | * @param bool $stripe_non_utf8 |
|
| 689 | * @param bool $html_entity_decode |
||
| 690 | * @param bool|null $convert_array <strong>false</strong> => Keep the array.<br /> |
||
| 691 | 1 | * <strong>true</strong> => Convert to string var1,var2,var3...<br /> |
|
| 692 | 1 | * <strong>null</strong> => Convert the array into null, every time. |
|
| 693 | * |
||
| 694 | 1 | * @return mixed |
|
| 695 | 1 | */ |
|
| 696 | public function escape($var = '', $stripe_non_utf8 = true, $html_entity_decode = false, $convert_array = false) |
||
| 810 | |||
| 811 | /** |
||
| 812 | 1 | * Execute select/insert/update/delete sql-queries. |
|
| 813 | 1 | * |
|
| 814 | * @param string $query sql-query |
||
| 815 | * @param bool $useCache use cache? |
||
| 816 | 1 | * @param int $cacheTTL cache-ttl in seconds |
|
| 817 | * |
||
| 818 | * @return mixed "array" by "<b>SELECT</b>"-queries<br /> |
||
| 819 | 8 | * "int" (insert_id) by "<b>INSERT</b>"-queries<br /> |
|
| 820 | * "int" (affected_rows) by "<b>UPDATE / DELETE</b>"-queries<br /> |
||
| 821 | * "true" by e.g. "DROP"-queries<br /> |
||
| 822 | 8 | * "false" on error |
|
| 823 | * |
||
| 824 | 8 | * @throws QueryException |
|
| 825 | */ |
||
| 826 | public static function execSQL($query, $useCache = false, $cacheTTL = 3600) |
||
| 873 | |||
| 874 | /** |
||
| 875 | * Get all table-names via "SHOW TABLES". |
||
| 876 | * |
||
| 877 | * @return array |
||
| 878 | */ |
||
| 879 | public function getAllTables() |
||
| 886 | 3 | ||
| 887 | /** |
||
| 888 | * @return Debug |
||
| 889 | 3 | */ |
|
| 890 | 3 | public function getDebugger() |
|
| 894 | 1 | ||
| 895 | /** |
||
| 896 | * Get errors from "$this->_errors". |
||
| 897 | 1 | * |
|
| 898 | 1 | * @return array |
|
| 899 | 1 | */ |
|
| 900 | 1 | public function getErrors() |
|
| 904 | 1 | ||
| 905 | 3 | /** |
|
| 906 | * getInstance() |
||
| 907 | * |
||
| 908 | 3 | * @param string $hostname |
|
| 909 | * @param string $username |
||
| 910 | 3 | * @param string $password |
|
| 911 | * @param string $database |
||
| 912 | 1 | * @param string $port default is (int)3306 |
|
| 913 | * @param string $charset default is 'utf8' or 'utf8mb4' (if supported) |
||
| 914 | * @param bool|string $exit_on_error use a empty string "" or false to disable it |
||
| 915 | * @param bool|string $echo_on_error use a empty string "" or false to disable it |
||
| 916 | * @param string $logger_class_name |
||
| 917 | 1 | * @param string $logger_level |
|
| 918 | * @param bool|string $session_to_db use a empty string "" or false to disable it |
||
| 919 | 1 | * |
|
| 920 | * @return \voku\db\DB |
||
| 921 | 1 | */ |
|
| 922 | 1 | public static function getInstance($hostname = '', $username = '', $password = '', $database = '', $port = '', $charset = '', $exit_on_error = '', $echo_on_error = '', $logger_class_name = '', $logger_level = '', $session_to_db = '') |
|
| 968 | |||
| 969 | /** |
||
| 970 | * Get the mysqli-link (link identifier returned by mysqli-connect). |
||
| 971 | * |
||
| 972 | * @return \mysqli |
||
| 973 | */ |
||
| 974 | public function getLink() |
||
| 978 | |||
| 979 | /** |
||
| 980 | * Get the current charset. |
||
| 981 | * |
||
| 982 | * @return string |
||
| 983 | */ |
||
| 984 | public function get_charset() |
||
| 988 | |||
| 989 | /** |
||
| 990 | * Check if we are in a transaction. |
||
| 991 | * |
||
| 992 | * @return bool |
||
| 993 | */ |
||
| 994 | public function inTransaction() |
||
| 998 | 7 | ||
| 999 | 7 | /** |
|
| 1000 | 5 | * Execute a "insert"-query. |
|
| 1001 | 5 | * |
|
| 1002 | 7 | * @param string $table |
|
| 1003 | 5 | * @param array $data |
|
| 1004 | 5 | * @param string|null $databaseName <p>Use <strong>null</strong> if you will use the current database.</p> |
|
| 1005 | * |
||
| 1006 | 7 | * @return false|int <p>false on error</p> |
|
| 1007 | * |
||
| 1008 | 7 | * @throws QueryException |
|
| 1009 | */ |
||
| 1010 | public function insert($table, array $data = array(), $databaseName = null) |
||
| 1037 | |||
| 1038 | 1 | /** |
|
| 1039 | 1 | * Returns the auto generated id used in the last query. |
|
| 1040 | * |
||
| 1041 | 1 | * @return int|string |
|
| 1042 | */ |
||
| 1043 | public function insert_id() |
||
| 1047 | |||
| 1048 | /** |
||
| 1049 | * Check if db-connection is ready. |
||
| 1050 | * |
||
| 1051 | * @return boolean |
||
| 1052 | */ |
||
| 1053 | public function isReady() |
||
| 1057 | |||
| 1058 | 1 | /** |
|
| 1059 | * Get the last sql-error. |
||
| 1060 | * |
||
| 1061 | * @return string|false <p>false === there was no error</p> |
||
| 1062 | 1 | */ |
|
| 1063 | 1 | public function lastError() |
|
| 1069 | 1 | ||
| 1070 | 1 | /** |
|
| 1071 | * Execute a sql-multi-query. |
||
| 1072 | 1 | * |
|
| 1073 | * @param string $sql |
||
| 1074 | 1 | * |
|
| 1075 | 1 | * @return false|Result[] "Result"-Array by "<b>SELECT</b>"-queries<br /> |
|
| 1076 | 1 | * "boolean" by only "<b>INSERT</b>"-queries<br /> |
|
| 1077 | * "boolean" by only (affected_rows) by "<b>UPDATE / DELETE</b>"-queries<br /> |
||
| 1078 | 1 | * "boolean" by only by e.g. "DROP"-queries<br /> |
|
| 1079 | * |
||
| 1080 | 1 | * @throws QueryException |
|
| 1081 | 1 | */ |
|
| 1082 | 1 | public function multi_query($sql) |
|
| 1144 | |||
| 1145 | /** |
||
| 1146 | * Pings a server connection, or tries to reconnect |
||
| 1147 | * if the connection has gone down. |
||
| 1148 | 4 | * |
|
| 1149 | 4 | * @return boolean |
|
| 1150 | */ |
||
| 1151 | 4 | public function ping() |
|
| 1165 | |||
| 1166 | /** |
||
| 1167 | * Get a new "Prepare"-Object for your sql-query. |
||
| 1168 | * |
||
| 1169 | 4 | * @param string $query |
|
| 1170 | * |
||
| 1171 | 4 | * @return Prepare |
|
| 1172 | */ |
||
| 1173 | public function prepare($query) |
||
| 1177 | |||
| 1178 | /** |
||
| 1179 | 2 | * Execute a sql-query and return the result-array for select-statements. |
|
| 1180 | * |
||
| 1181 | * @param $query |
||
| 1182 | 2 | * |
|
| 1183 | 1 | * @return mixed |
|
| 1184 | 1 | * @deprecated |
|
| 1185 | 1 | * @throws \Exception |
|
| 1186 | 1 | */ |
|
| 1187 | 1 | public static function qry($query) |
|
| 1212 | |||
| 1213 | /** |
||
| 1214 | 2 | * Execute a sql-query. |
|
| 1215 | * |
||
| 1216 | 2 | * @param string $sql <p>The sql query-string.</p> |
|
| 1217 | 2 | * |
|
| 1218 | 2 | * @param array|boolean $params <p> |
|
| 1219 | 2 | * "array" of sql-query-parameters<br/> |
|
| 1220 | 2 | * "false" if you don't need any parameter (default)<br/> |
|
| 1221 | * </p> |
||
| 1222 | 2 | * |
|
| 1223 | * @return bool|int|Result <p> |
||
| 1224 | * "Result" by "<b>SELECT</b>"-queries<br /> |
||
| 1225 | * "int" (insert_id) by "<b>INSERT / REPLACE</b>"-queries<br /> |
||
| 1226 | * "int" (affected_rows) by "<b>UPDATE / DELETE</b>"-queries<br /> |
||
| 1227 | * "true" by e.g. "DROP"-queries<br /> |
||
| 1228 | * "false" on error |
||
| 1229 | * </p> |
||
| 1230 | * |
||
| 1231 | * @throws QueryException |
||
| 1232 | */ |
||
| 1233 | public function query($sql = '', $params = false) |
||
| 1307 | 1 | ||
| 1308 | 1 | /** |
|
| 1309 | * Error-handling for the sql-query. |
||
| 1310 | 23 | * |
|
| 1311 | 1 | * @param string $errorMsg |
|
| 1312 | 1 | * @param string $sql |
|
| 1313 | * @param array|bool $sqlParams false if there wasn't any parameter |
||
| 1314 | 23 | * |
|
| 1315 | 1 | * @throws QueryException |
|
| 1316 | 1 | * @throws DBGoneAwayException |
|
| 1317 | * |
||
| 1318 | 23 | * @return bool |
|
| 1319 | 2 | */ |
|
| 1320 | 2 | View Code Duplication | protected function queryErrorHandling($errorMsg, $sql, $sqlParams = false) |
| 1348 | 2 | ||
| 1349 | /** |
||
| 1350 | 23 | * Quote && Escape e.g. a table name string. |
|
| 1351 | 1 | * |
|
| 1352 | 1 | * @param string $str |
|
| 1353 | * |
||
| 1354 | 23 | * @return string |
|
| 1355 | 2 | */ |
|
| 1356 | 2 | public function quote_string($str) |
|
| 1369 | 23 | ||
| 1370 | 23 | /** |
|
| 1371 | 23 | * Reconnect to the MySQL-Server. |
|
| 1372 | * |
||
| 1373 | 23 | * @param bool $checkViaPing |
|
| 1374 | 23 | * |
|
| 1375 | 23 | * @return bool |
|
| 1376 | 23 | */ |
|
| 1377 | public function reconnect($checkViaPing = false) |
||
| 1392 | |||
| 1393 | 23 | /** |
|
| 1394 | * Execute a "replace"-query. |
||
| 1395 | 23 | * |
|
| 1396 | * @param string $table |
||
| 1397 | 23 | * @param array $data |
|
| 1398 | 1 | * @param null|string $databaseName <p>Use <strong>null</strong> if you will use the current database.</p> |
|
| 1399 | 23 | * |
|
| 1400 | 23 | * @return false|int <p>false on error</p> |
|
| 1401 | 23 | * |
|
| 1402 | * @throws QueryException |
||
| 1403 | 23 | */ |
|
| 1404 | 1 | public function replace($table, array $data = array(), $databaseName = null) |
|
| 1445 | |||
| 1446 | /** |
||
| 1447 | 1 | * Rollback in a transaction. |
|
| 1448 | */ |
||
| 1449 | 1 | public function rollback() |
|
| 1462 | |||
| 1463 | 1 | /** |
|
| 1464 | * Try to secure a variable, so can you use it in sql-queries. |
||
| 1465 | * |
||
| 1466 | 1 | * <p> |
|
| 1467 | * <strong>int:</strong> (also strings that contains only an int-value)<br /> |
||
| 1468 | 1 | * 1. parse into "int" |
|
| 1469 | 1 | * </p><br /> |
|
| 1470 | * |
||
| 1471 | 1 | * <p> |
|
| 1472 | * <strong>float:</strong><br /> |
||
| 1473 | * 1. return "float" |
||
| 1474 | 1 | * </p><br /> |
|
| 1475 | 1 | * |
|
| 1476 | * <p> |
||
| 1477 | 1 | * <strong>string:</strong><br /> |
|
| 1478 | * 1. check if the string isn't a default mysql-time-function e.g. 'CURDATE()'<br /> |
||
| 1479 | * 2. trim whitespace<br /> |
||
| 1480 | * 3. trim '<br /> |
||
| 1481 | 1 | * 4. escape the string (and remove non utf-8 chars)<br /> |
|
| 1482 | 1 | * 5. trim ' again (because we maybe removed some chars)<br /> |
|
| 1483 | * 6. add ' around the new string<br /> |
||
| 1484 | 1 | * </p><br /> |
|
| 1485 | 1 | * |
|
| 1486 | * <p> |
||
| 1487 | 1 | * <strong>array:</strong><br /> |
|
| 1488 | * 1. return null |
||
| 1489 | * </p><br /> |
||
| 1490 | 1 | * |
|
| 1491 | * <p> |
||
| 1492 | 1 | * <strong>object:</strong><br /> |
|
| 1493 | 1 | * 1. return false |
|
| 1494 | 1 | * </p><br /> |
|
| 1495 | * |
||
| 1496 | 1 | * <p> |
|
| 1497 | * <strong>null:</strong><br /> |
||
| 1498 | * 1. return null |
||
| 1499 | * </p> |
||
| 1500 | 1 | * |
|
| 1501 | * @param mixed $var |
||
| 1502 | 1 | * |
|
| 1503 | * @return mixed |
||
| 1504 | */ |
||
| 1505 | public function secure($var) |
||
| 1531 | 2 | ||
| 1532 | /** |
||
| 1533 | * Execute a "select"-query. |
||
| 1534 | 6 | * |
|
| 1535 | * @param string $table |
||
| 1536 | 6 | * @param string|array $where |
|
| 1537 | 2 | * @param string|null $databaseName <p>Use <strong>null</strong> if you will use the current database.</p> |
|
| 1538 | 6 | * |
|
| 1539 | 4 | * @return false|Result <p>false on error</p> |
|
| 1540 | 4 | * |
|
| 1541 | 1 | * @throws QueryException |
|
| 1542 | */ |
||
| 1543 | View Code Duplication | public function select($table, $where = '1=1', $databaseName = null) |
|
| 1570 | 1 | ||
| 1571 | /** |
||
| 1572 | 1 | * Set the current charset. |
|
| 1573 | * |
||
| 1574 | * @param string $charset |
||
| 1575 | 2 | * |
|
| 1576 | 1 | * @return bool |
|
| 1577 | 2 | */ |
|
| 1578 | 2 | public function set_charset($charset) |
|
| 1600 | |||
| 1601 | /** |
||
| 1602 | * Set the option to convert null to "''" (empty string). |
||
| 1603 | 20 | * |
|
| 1604 | * Used in secure() => select(), insert(), update(), delete() |
||
| 1605 | * |
||
| 1606 | 20 | * @param $bool |
|
| 1607 | */ |
||
| 1608 | 20 | public function set_convert_null_to_empty_string($bool) |
|
| 1612 | |||
| 1613 | /** |
||
| 1614 | 20 | * Enables or disables internal report functions |
|
| 1615 | 5 | * |
|
| 1616 | 20 | * @link http://php.net/manual/en/function.mysqli-report.php |
|
| 1617 | 16 | * |
|
| 1618 | 16 | * @param int $flags <p> |
|
| 1619 | 1 | * <table> |
|
| 1620 | * Supported flags |
||
| 1621 | * <tr valign="top"> |
||
| 1622 | 20 | * <td>Name</td> |
|
| 1623 | * <td>Description</td> |
||
| 1624 | * </tr> |
||
| 1625 | * <tr valign="top"> |
||
| 1626 | 20 | * <td><b>MYSQLI_REPORT_OFF</b></td> |
|
| 1627 | * <td>Turns reporting off</td> |
||
| 1628 | 20 | * </tr> |
|
| 1629 | * <tr valign="top"> |
||
| 1630 | * <td><b>MYSQLI_REPORT_ERROR</b></td> |
||
| 1631 | * <td>Report errors from mysqli function calls</td> |
||
| 1632 | * </tr> |
||
| 1633 | * <tr valign="top"> |
||
| 1634 | * <td><b>MYSQLI_REPORT_STRICT</b></td> |
||
| 1635 | * <td> |
||
| 1636 | 1 | * Throw <b>mysqli_sql_exception</b> for errors |
|
| 1637 | * instead of warnings |
||
| 1638 | 1 | * </td> |
|
| 1639 | * </tr> |
||
| 1640 | 1 | * <tr valign="top"> |
|
| 1641 | * <td><b>MYSQLI_REPORT_INDEX</b></td> |
||
| 1642 | * <td>Report if no index or bad index was used in a query</td> |
||
| 1643 | * </tr> |
||
| 1644 | * <tr valign="top"> |
||
| 1645 | * <td><b>MYSQLI_REPORT_ALL</b></td> |
||
| 1646 | 9 | * <td>Set all options (report all)</td> |
|
| 1647 | * </tr> |
||
| 1648 | 9 | * </table> |
|
| 1649 | * </p> |
||
| 1650 | * |
||
| 1651 | * @return bool |
||
| 1652 | */ |
||
| 1653 | public function set_mysqli_report($flags) |
||
| 1657 | |||
| 1658 | /** |
||
| 1659 | * Show config errors by throw exceptions. |
||
| 1660 | * |
||
| 1661 | * @return bool |
||
| 1662 | * |
||
| 1663 | * @throws \InvalidArgumentException |
||
| 1664 | */ |
||
| 1665 | public function showConfigError() |
||
| 1693 | |||
| 1694 | /** |
||
| 1695 | * alias: "beginTransaction()" |
||
| 1696 | */ |
||
| 1697 | public function startTransaction() |
||
| 1701 | |||
| 1702 | /** |
||
| 1703 | * Execute a "update"-query. |
||
| 1704 | * |
||
| 1705 | * @param string $table |
||
| 1706 | * @param array $data |
||
| 1707 | * @param array|string $where |
||
| 1708 | * @param null|string $databaseName <p>Use <strong>null</strong> if you will use the current database.</p> |
||
| 1709 | * |
||
| 1710 | * @return false|int <p>false on error</p> |
||
| 1711 | * |
||
| 1712 | * @throws QueryException |
||
| 1713 | */ |
||
| 1714 | public function update($table, array $data = array(), $where = '1=1', $databaseName = null) |
||
| 1749 | |||
| 1750 | } |
||
| 1751 |
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.