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() |
||
| 664 | 33 | ||
| 665 | 33 | /** |
|
| 666 | 33 | * Get all errors from "$this->_errors". |
|
| 667 | * |
||
| 668 | 33 | * @return array|false <p>false === on errors</p> |
|
| 669 | 33 | */ |
|
| 670 | public function errors() |
||
| 676 | 33 | ||
| 677 | /** |
||
| 678 | * Escape: Use "mysqli_real_escape_string" and clean non UTF-8 chars + some extra optional stuff. |
||
| 679 | * |
||
| 680 | 5 | * @param mixed $var boolean: convert into "integer"<br /> |
|
| 681 | * int: int (don't change it)<br /> |
||
| 682 | * float: float (don't change it)<br /> |
||
| 683 | 33 | * null: null (don't change it)<br /> |
|
| 684 | * array: run escape() for every key => value<br /> |
||
| 685 | * string: run UTF8::cleanup() and mysqli_real_escape_string()<br /> |
||
| 686 | * @param bool $stripe_non_utf8 |
||
| 687 | 3 | * @param bool $html_entity_decode |
|
| 688 | 3 | * @param bool|null $convert_array <strong>false</strong> => Keep the array.<br /> |
|
| 689 | * <strong>true</strong> => Convert to string var1,var2,var3...<br /> |
||
| 690 | * <strong>null</strong> => Convert the array into null, every time. |
||
| 691 | 1 | * |
|
| 692 | 1 | * @return mixed |
|
| 693 | */ |
||
| 694 | 1 | public function escape($var = '', $stripe_non_utf8 = true, $html_entity_decode = false, $convert_array = false) |
|
| 808 | |||
| 809 | 1 | /** |
|
| 810 | * Execute select/insert/update/delete sql-queries. |
||
| 811 | * |
||
| 812 | 1 | * @param string $query sql-query |
|
| 813 | 1 | * @param bool $useCache use cache? |
|
| 814 | * @param int $cacheTTL cache-ttl in seconds |
||
| 815 | * |
||
| 816 | 1 | * @return mixed "array" by "<b>SELECT</b>"-queries<br /> |
|
| 817 | * "int" (insert_id) by "<b>INSERT</b>"-queries<br /> |
||
| 818 | * "int" (affected_rows) by "<b>UPDATE / DELETE</b>"-queries<br /> |
||
| 819 | 8 | * "true" by e.g. "DROP"-queries<br /> |
|
| 820 | * "false" on error |
||
| 821 | * |
||
| 822 | 8 | * @throws QueryException |
|
| 823 | */ |
||
| 824 | 8 | public static function execSQL($query, $useCache = false, $cacheTTL = 3600) |
|
| 871 | |||
| 872 | /** |
||
| 873 | * Get all table-names via "SHOW TABLES". |
||
| 874 | * |
||
| 875 | * @return array |
||
| 876 | */ |
||
| 877 | public function getAllTables() |
||
| 884 | |||
| 885 | /** |
||
| 886 | 3 | * @return Debug |
|
| 887 | */ |
||
| 888 | public function getDebugger() |
||
| 892 | 3 | ||
| 893 | 1 | /** |
|
| 894 | 1 | * Get errors from "$this->_errors". |
|
| 895 | * |
||
| 896 | * @return array |
||
| 897 | 1 | */ |
|
| 898 | 1 | public function getErrors() |
|
| 902 | |||
| 903 | /** |
||
| 904 | 1 | * getInstance() |
|
| 905 | 3 | * |
|
| 906 | * @param string $hostname |
||
| 907 | * @param string $username |
||
| 908 | 3 | * @param string $password |
|
| 909 | * @param string $database |
||
| 910 | 3 | * @param string $port default is (int)3306 |
|
| 911 | * @param string $charset default is 'utf8' or 'utf8mb4' (if supported) |
||
| 912 | 1 | * @param bool|string $exit_on_error use a empty string "" or false to disable it |
|
| 913 | * @param bool|string $echo_on_error use a empty string "" or false to disable it |
||
| 914 | * @param string $logger_class_name |
||
| 915 | * @param string $logger_level |
||
| 916 | * @param bool|string $session_to_db use a empty string "" or false to disable it |
||
| 917 | 1 | * |
|
| 918 | * @return \voku\db\DB |
||
| 919 | 1 | */ |
|
| 920 | public static function getInstance($hostname = '', $username = '', $password = '', $database = '', $port = '', $charset = '', $exit_on_error = '', $echo_on_error = '', $logger_class_name = '', $logger_level = '', $session_to_db = '') |
||
| 966 | |||
| 967 | /** |
||
| 968 | * Get the mysqli-link (link identifier returned by mysqli-connect). |
||
| 969 | * |
||
| 970 | * @return \mysqli |
||
| 971 | */ |
||
| 972 | public function getLink() |
||
| 976 | |||
| 977 | /** |
||
| 978 | * Get the current charset. |
||
| 979 | * |
||
| 980 | * @return string |
||
| 981 | */ |
||
| 982 | public function get_charset() |
||
| 986 | |||
| 987 | /** |
||
| 988 | * Check if we are in a transaction. |
||
| 989 | * |
||
| 990 | * @return bool |
||
| 991 | */ |
||
| 992 | public function inTransaction() |
||
| 996 | 7 | ||
| 997 | /** |
||
| 998 | 7 | * Execute a "insert"-query. |
|
| 999 | 7 | * |
|
| 1000 | 5 | * @param string $table |
|
| 1001 | 5 | * @param array $data |
|
| 1002 | 7 | * @param string|null $databaseName <p>Use <strong>null</strong> if you will use the current database.</p> |
|
| 1003 | 5 | * |
|
| 1004 | 5 | * @return false|int <p>false on error</p> |
|
| 1005 | * |
||
| 1006 | 7 | * @throws QueryException |
|
| 1007 | */ |
||
| 1008 | 7 | public function insert($table, array $data = array(), $databaseName = null) |
|
| 1035 | |||
| 1036 | 1 | /** |
|
| 1037 | * Returns the auto generated id used in the last query. |
||
| 1038 | 1 | * |
|
| 1039 | 1 | * @return int|string |
|
| 1040 | */ |
||
| 1041 | 1 | public function insert_id() |
|
| 1045 | |||
| 1046 | /** |
||
| 1047 | * Check if db-connection is ready. |
||
| 1048 | * |
||
| 1049 | * @return boolean |
||
| 1050 | */ |
||
| 1051 | public function isReady() |
||
| 1055 | |||
| 1056 | 1 | /** |
|
| 1057 | * Get the last sql-error. |
||
| 1058 | 1 | * |
|
| 1059 | * @return string|false <p>false === there was no error</p> |
||
| 1060 | */ |
||
| 1061 | public function lastError() |
||
| 1067 | |||
| 1068 | 1 | /** |
|
| 1069 | 1 | * Execute a sql-multi-query. |
|
| 1070 | 1 | * |
|
| 1071 | * @param string $sql |
||
| 1072 | 1 | * |
|
| 1073 | * @return false|Result[] "Result"-Array by "<b>SELECT</b>"-queries<br /> |
||
| 1074 | 1 | * "boolean" by only "<b>INSERT</b>"-queries<br /> |
|
| 1075 | 1 | * "boolean" by only (affected_rows) by "<b>UPDATE / DELETE</b>"-queries<br /> |
|
| 1076 | 1 | * "boolean" by only by e.g. "DROP"-queries<br /> |
|
| 1077 | * |
||
| 1078 | 1 | * @throws QueryException |
|
| 1079 | */ |
||
| 1080 | 1 | public function multi_query($sql) |
|
| 1142 | 4 | ||
| 1143 | /** |
||
| 1144 | * Pings a server connection, or tries to reconnect |
||
| 1145 | * if the connection has gone down. |
||
| 1146 | * |
||
| 1147 | * @return boolean |
||
| 1148 | 4 | */ |
|
| 1149 | 4 | public function ping() |
|
| 1163 | |||
| 1164 | /** |
||
| 1165 | * Selects a different database than the one specified on construction. |
||
| 1166 | * |
||
| 1167 | * @param string $database <p>Database name to switch to.</p> |
||
| 1168 | * |
||
| 1169 | 4 | * @return bool <p>Boolean true on success, false otherwise.</p> |
|
| 1170 | */ |
||
| 1171 | 4 | public function select_db($database) |
|
| 1179 | 2 | ||
| 1180 | /** |
||
| 1181 | * Get a new "Prepare"-Object for your sql-query. |
||
| 1182 | 2 | * |
|
| 1183 | 1 | * @param string $query |
|
| 1184 | 1 | * |
|
| 1185 | 1 | * @return Prepare |
|
| 1186 | 1 | */ |
|
| 1187 | 1 | public function prepare($query) |
|
| 1191 | 2 | ||
| 1192 | /** |
||
| 1193 | 2 | * Execute a sql-query and return the result-array for select-statements. |
|
| 1194 | * |
||
| 1195 | * @param $query |
||
| 1196 | * |
||
| 1197 | * @return mixed |
||
| 1198 | * @deprecated |
||
| 1199 | * @throws \Exception |
||
| 1200 | */ |
||
| 1201 | 2 | public static function qry($query) |
|
| 1226 | |||
| 1227 | /** |
||
| 1228 | * Execute a sql-query. |
||
| 1229 | * |
||
| 1230 | * @param string $sql <p>The sql query-string.</p> |
||
| 1231 | * |
||
| 1232 | * @param array|boolean $params <p> |
||
| 1233 | * "array" of sql-query-parameters<br/> |
||
| 1234 | * "false" if you don't need any parameter (default)<br/> |
||
| 1235 | * </p> |
||
| 1236 | 21 | * |
|
| 1237 | * @return bool|int|Result <p> |
||
| 1238 | * "Result" by "<b>SELECT</b>"-queries<br /> |
||
| 1239 | 21 | * "int" (insert_id) by "<b>INSERT / REPLACE</b>"-queries<br /> |
|
| 1240 | * "int" (affected_rows) by "<b>UPDATE / DELETE</b>"-queries<br /> |
||
| 1241 | 21 | * "true" by e.g. "DROP"-queries<br /> |
|
| 1242 | 2 | * "false" on error |
|
| 1243 | * </p> |
||
| 1244 | 2 | * |
|
| 1245 | * @throws QueryException |
||
| 1246 | */ |
||
| 1247 | 20 | public function query($sql = '', $params = false) |
|
| 1321 | |||
| 1322 | 23 | /** |
|
| 1323 | 2 | * Error-handling for the sql-query. |
|
| 1324 | 2 | * |
|
| 1325 | * @param string $errorMsg |
||
| 1326 | 23 | * @param string $sql |
|
| 1327 | 4 | * @param array|bool $sqlParams false if there wasn't any parameter |
|
| 1328 | 4 | * |
|
| 1329 | * @throws QueryException |
||
| 1330 | 23 | * @throws DBGoneAwayException |
|
| 1331 | 1 | * |
|
| 1332 | 1 | * @return bool |
|
| 1333 | */ |
||
| 1334 | 23 | View Code Duplication | protected function queryErrorHandling($errorMsg, $sql, $sqlParams = false) |
| 1362 | 1 | ||
| 1363 | 1 | /** |
|
| 1364 | * Quote && Escape e.g. a table name string. |
||
| 1365 | 2 | * |
|
| 1366 | 23 | * @param string $str |
|
| 1367 | * |
||
| 1368 | * @return string |
||
| 1369 | 23 | */ |
|
| 1370 | 23 | public function quote_string($str) |
|
| 1383 | 23 | ||
| 1384 | 23 | /** |
|
| 1385 | * Reconnect to the MySQL-Server. |
||
| 1386 | 23 | * |
|
| 1387 | 23 | * @param bool $checkViaPing |
|
| 1388 | 23 | * |
|
| 1389 | * @return bool |
||
| 1390 | 23 | */ |
|
| 1391 | 23 | public function reconnect($checkViaPing = false) |
|
| 1406 | |||
| 1407 | 23 | /** |
|
| 1408 | 23 | * Execute a "replace"-query. |
|
| 1409 | 23 | * |
|
| 1410 | * @param string $table |
||
| 1411 | 23 | * @param array $data |
|
| 1412 | 2 | * @param null|string $databaseName <p>Use <strong>null</strong> if you will use the current database.</p> |
|
| 1413 | 2 | * |
|
| 1414 | * @return false|int <p>false on error</p> |
||
| 1415 | 23 | * |
|
| 1416 | 23 | * @throws QueryException |
|
| 1417 | */ |
||
| 1418 | 23 | public function replace($table, array $data = array(), $databaseName = null) |
|
| 1459 | |||
| 1460 | /** |
||
| 1461 | * Rollback in a transaction and end the transaction. |
||
| 1462 | * |
||
| 1463 | 1 | * @return bool <p>Boolean true on success, false otherwise.</p> |
|
| 1464 | */ |
||
| 1465 | View Code Duplication | public function rollback() |
|
| 1477 | 1 | ||
| 1478 | |||
| 1479 | /** |
||
| 1480 | * Commits the current transaction and end the transaction. |
||
| 1481 | 1 | * |
|
| 1482 | 1 | * @return bool <p>Boolean true on success, false otherwise.</p> |
|
| 1483 | */ |
||
| 1484 | 1 | View Code Duplication | public function commit() |
| 1496 | 1 | ||
| 1497 | /** |
||
| 1498 | * Try to secure a variable, so can you use it in sql-queries. |
||
| 1499 | * |
||
| 1500 | 1 | * <p> |
|
| 1501 | * <strong>int:</strong> (also strings that contains only an int-value)<br /> |
||
| 1502 | 1 | * 1. parse into "int" |
|
| 1503 | * </p><br /> |
||
| 1504 | * |
||
| 1505 | * <p> |
||
| 1506 | * <strong>float:</strong><br /> |
||
| 1507 | * 1. return "float" |
||
| 1508 | * </p><br /> |
||
| 1509 | * |
||
| 1510 | * <p> |
||
| 1511 | * <strong>string:</strong><br /> |
||
| 1512 | * 1. check if the string isn't a default mysql-time-function e.g. 'CURDATE()'<br /> |
||
| 1513 | * 2. trim whitespace<br /> |
||
| 1514 | * 3. trim '<br /> |
||
| 1515 | * 4. escape the string (and remove non utf-8 chars)<br /> |
||
| 1516 | * 5. trim ' again (because we maybe removed some chars)<br /> |
||
| 1517 | 6 | * 6. add ' around the new string<br /> |
|
| 1518 | * </p><br /> |
||
| 1519 | * |
||
| 1520 | 6 | * <p> |
|
| 1521 | * <strong>array:</strong><br /> |
||
| 1522 | 6 | * 1. return null |
|
| 1523 | 1 | * </p><br /> |
|
| 1524 | * |
||
| 1525 | 1 | * <p> |
|
| 1526 | * <strong>object:</strong><br /> |
||
| 1527 | * 1. return false |
||
| 1528 | 6 | * </p><br /> |
|
| 1529 | 2 | * |
|
| 1530 | * <p> |
||
| 1531 | 2 | * <strong>null:</strong><br /> |
|
| 1532 | * 1. return null |
||
| 1533 | * </p> |
||
| 1534 | 6 | * |
|
| 1535 | * @param mixed $var |
||
| 1536 | 6 | * |
|
| 1537 | 2 | * @return mixed |
|
| 1538 | 6 | */ |
|
| 1539 | 4 | public function secure($var) |
|
| 1565 | |||
| 1566 | /** |
||
| 1567 | 2 | * Execute a "select"-query. |
|
| 1568 | * |
||
| 1569 | 2 | * @param string $table |
|
| 1570 | 1 | * @param string|array $where |
|
| 1571 | * @param string|null $databaseName <p>Use <strong>null</strong> if you will use the current database.</p> |
||
| 1572 | 1 | * |
|
| 1573 | * @return false|Result <p>false on error</p> |
||
| 1574 | * |
||
| 1575 | 2 | * @throws QueryException |
|
| 1576 | 1 | */ |
|
| 1577 | 2 | View Code Duplication | public function select($table, $where = '1=1', $databaseName = null) |
| 1604 | |||
| 1605 | /** |
||
| 1606 | 20 | * Set the current charset. |
|
| 1607 | * |
||
| 1608 | 20 | * @param string $charset |
|
| 1609 | 1 | * |
|
| 1610 | * @return bool |
||
| 1611 | 1 | */ |
|
| 1612 | public function set_charset($charset) |
||
| 1634 | |||
| 1635 | /** |
||
| 1636 | 1 | * Set the option to convert null to "''" (empty string). |
|
| 1637 | * |
||
| 1638 | 1 | * Used in secure() => select(), insert(), update(), delete() |
|
| 1639 | * |
||
| 1640 | 1 | * @param $bool |
|
| 1641 | */ |
||
| 1642 | public function set_convert_null_to_empty_string($bool) |
||
| 1646 | 9 | ||
| 1647 | /** |
||
| 1648 | 9 | * Enables or disables internal report functions |
|
| 1649 | * |
||
| 1650 | * @link http://php.net/manual/en/function.mysqli-report.php |
||
| 1651 | * |
||
| 1652 | * @param int $flags <p> |
||
| 1653 | * <table> |
||
| 1654 | * Supported flags |
||
| 1655 | * <tr valign="top"> |
||
| 1656 | * <td>Name</td> |
||
| 1657 | * <td>Description</td> |
||
| 1658 | * </tr> |
||
| 1659 | * <tr valign="top"> |
||
| 1660 | * <td><b>MYSQLI_REPORT_OFF</b></td> |
||
| 1661 | * <td>Turns reporting off</td> |
||
| 1662 | * </tr> |
||
| 1663 | * <tr valign="top"> |
||
| 1664 | * <td><b>MYSQLI_REPORT_ERROR</b></td> |
||
| 1665 | * <td>Report errors from mysqli function calls</td> |
||
| 1666 | 2 | * </tr> |
|
| 1667 | * <tr valign="top"> |
||
| 1668 | 2 | * <td><b>MYSQLI_REPORT_STRICT</b></td> |
|
| 1669 | * <td> |
||
| 1670 | 2 | * Throw <b>mysqli_sql_exception</b> for errors |
|
| 1671 | 2 | * instead of warnings |
|
| 1672 | 2 | * </td> |
|
| 1673 | 2 | * </tr> |
|
| 1674 | * <tr valign="top"> |
||
| 1675 | * <td><b>MYSQLI_REPORT_INDEX</b></td> |
||
| 1676 | * <td>Report if no index or bad index was used in a query</td> |
||
| 1677 | * </tr> |
||
| 1678 | * <tr valign="top"> |
||
| 1679 | * <td><b>MYSQLI_REPORT_ALL</b></td> |
||
| 1680 | * <td>Set all options (report all)</td> |
||
| 1681 | * </tr> |
||
| 1682 | * </table> |
||
| 1683 | * </p> |
||
| 1684 | * |
||
| 1685 | * @return bool |
||
| 1686 | */ |
||
| 1687 | public function set_mysqli_report($flags) |
||
| 1691 | 2 | ||
| 1692 | 2 | /** |
|
| 1693 | * Show config errors by throw exceptions. |
||
| 1694 | * |
||
| 1695 | * @return bool |
||
| 1696 | * |
||
| 1697 | * @throws \InvalidArgumentException |
||
| 1698 | */ |
||
| 1699 | public function showConfigError() |
||
| 1727 | |||
| 1728 | /** |
||
| 1729 | * alias: "beginTransaction()" |
||
| 1730 | */ |
||
| 1731 | public function startTransaction() |
||
| 1735 | |||
| 1736 | /** |
||
| 1737 | * Execute a "update"-query. |
||
| 1738 | * |
||
| 1739 | * @param string $table |
||
| 1740 | * @param array $data |
||
| 1741 | * @param array|string $where |
||
| 1742 | * @param null|string $databaseName <p>Use <strong>null</strong> if you will use the current database.</p> |
||
| 1743 | * |
||
| 1744 | * @return false|int <p>false on error</p> |
||
| 1745 | * |
||
| 1746 | * @throws QueryException |
||
| 1747 | */ |
||
| 1748 | public function update($table, array $data = array(), $where = '1=1', $databaseName = null) |
||
| 1783 | |||
| 1784 | } |
||
| 1785 |
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.