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 |
||
| 13 | final class DB |
||
| 14 | { |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @var int |
||
| 18 | */ |
||
| 19 | public $query_count = 0; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @var \mysqli |
||
| 23 | */ |
||
| 24 | private $link = false; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @var bool |
||
| 28 | */ |
||
| 29 | private $connected = false; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var array |
||
| 33 | */ |
||
| 34 | private $mysqlDefaultTimeFunctions; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @var string |
||
| 38 | */ |
||
| 39 | private $hostname = ''; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @var string |
||
| 43 | */ |
||
| 44 | private $username = ''; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @var string |
||
| 48 | */ |
||
| 49 | private $password = ''; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @var string |
||
| 53 | */ |
||
| 54 | private $database = ''; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @var int |
||
| 58 | */ |
||
| 59 | private $port = 3306; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @var string |
||
| 63 | */ |
||
| 64 | private $charset = 'utf8'; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @var string |
||
| 68 | */ |
||
| 69 | private $socket = ''; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @var bool |
||
| 73 | */ |
||
| 74 | private $session_to_db = false; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * @var bool |
||
| 78 | */ |
||
| 79 | private $_in_transaction = false; |
||
| 80 | |||
| 81 | /** |
||
| 82 | * @var bool |
||
| 83 | */ |
||
| 84 | private $_convert_null_to_empty_string = false; |
||
| 85 | |||
| 86 | /** |
||
| 87 | * @var Debug |
||
| 88 | */ |
||
| 89 | private $_debug; |
||
| 90 | |||
| 91 | /** |
||
| 92 | * __construct() |
||
| 93 | * |
||
| 94 | * @param string $hostname |
||
| 95 | * @param string $username |
||
| 96 | * @param string $password |
||
| 97 | * @param string $database |
||
| 98 | * @param int $port |
||
| 99 | * @param string $charset |
||
| 100 | * @param boolean|string $exit_on_error use a empty string "" or false to disable it |
||
| 101 | * @param boolean|string $echo_on_error use a empty string "" or false to disable it |
||
| 102 | * @param string $logger_class_name |
||
| 103 | * @param string $logger_level 'TRACE', 'DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL' |
||
| 104 | * @param boolean|string $session_to_db use a empty string "" or false to disable it |
||
| 105 | */ |
||
| 106 | 10 | protected function __construct($hostname, $username, $password, $database, $port, $charset, $exit_on_error, $echo_on_error, $logger_class_name, $logger_level, $session_to_db) |
|
| 157 | |||
| 158 | /** |
||
| 159 | * Load the config from the constructor. |
||
| 160 | * |
||
| 161 | * @param string $hostname |
||
| 162 | * @param string $username |
||
| 163 | * @param string $password |
||
| 164 | * @param string $database |
||
| 165 | * @param int $port |
||
| 166 | * @param string $charset |
||
| 167 | * @param boolean|string $exit_on_error use a empty string "" or false to disable it |
||
| 168 | * @param boolean|string $echo_on_error use a empty string "" or false to disable it |
||
| 169 | * @param string $logger_class_name |
||
| 170 | * @param string $logger_level |
||
| 171 | * @param boolean|string $session_to_db use a empty string "" or false to disable it |
||
| 172 | * |
||
| 173 | * @return bool |
||
| 174 | */ |
||
| 175 | 10 | private function _loadConfig($hostname, $username, $password, $database, $port, $charset, $exit_on_error, $echo_on_error, $logger_class_name, $logger_level, $session_to_db) |
|
| 219 | |||
| 220 | /** |
||
| 221 | * Show config errors by throw exceptions. |
||
| 222 | * |
||
| 223 | * @return bool |
||
| 224 | * |
||
| 225 | * @throws \Exception |
||
| 226 | */ |
||
| 227 | 10 | public function showConfigError() |
|
| 228 | { |
||
| 229 | |||
| 230 | if ( |
||
| 231 | 10 | !$this->hostname |
|
| 232 | 10 | || |
|
| 233 | 9 | !$this->username |
|
| 234 | 9 | || |
|
| 235 | 8 | !$this->database |
|
| 236 | 10 | ) { |
|
| 237 | |||
| 238 | 3 | if (!$this->hostname) { |
|
| 239 | 1 | throw new \Exception('no-sql-hostname'); |
|
| 240 | } |
||
| 241 | |||
| 242 | 2 | if (!$this->username) { |
|
| 243 | 1 | throw new \Exception('no-sql-username'); |
|
| 244 | } |
||
| 245 | |||
| 246 | 1 | if (!$this->database) { |
|
| 247 | 1 | throw new \Exception('no-sql-database'); |
|
| 248 | } |
||
| 249 | |||
| 250 | return false; |
||
| 251 | } |
||
| 252 | |||
| 253 | 7 | return true; |
|
| 254 | } |
||
| 255 | |||
| 256 | /** |
||
| 257 | * Open a new connection to the MySQL server. |
||
| 258 | * |
||
| 259 | * @return boolean |
||
| 260 | */ |
||
| 261 | 9 | public function connect() |
|
| 262 | { |
||
| 263 | 9 | if ($this->isReady()) { |
|
| 264 | 1 | return true; |
|
| 265 | } |
||
| 266 | |||
| 267 | 9 | \mysqli_report(MYSQLI_REPORT_STRICT); |
|
| 268 | try { |
||
| 269 | 9 | $this->link = \mysqli_init(); |
|
|
|
|||
| 270 | |||
| 271 | 9 | if (Helper::isMysqlndIsUsed() === true) { |
|
| 272 | 9 | \mysqli_options($this->link, MYSQLI_OPT_INT_AND_FLOAT_NATIVE, true); |
|
| 273 | 9 | } |
|
| 274 | |||
| 275 | /** @noinspection PhpUsageOfSilenceOperatorInspection */ |
||
| 276 | 9 | $this->connected = @\mysqli_real_connect( |
|
| 277 | 9 | $this->link, |
|
| 278 | 9 | $this->hostname, |
|
| 279 | 9 | $this->username, |
|
| 280 | 9 | $this->password, |
|
| 281 | 9 | $this->database, |
|
| 282 | 9 | $this->port, |
|
| 283 | 9 | $this->socket |
|
| 284 | 9 | ); |
|
| 285 | 9 | } catch (\Exception $e) { |
|
| 286 | 3 | $this->_debug->displayError('Error connecting to mysql server: ' . $e->getMessage(), true); |
|
| 287 | } |
||
| 288 | 6 | \mysqli_report(MYSQLI_REPORT_OFF); |
|
| 289 | |||
| 290 | 6 | if (!$this->connected) { |
|
| 291 | $this->_debug->displayError('Error connecting to mysql server: ' . \mysqli_connect_error(), true); |
||
| 292 | } else { |
||
| 293 | 6 | $this->set_charset($this->charset); |
|
| 294 | } |
||
| 295 | |||
| 296 | 6 | return $this->isReady(); |
|
| 297 | } |
||
| 298 | |||
| 299 | /** |
||
| 300 | * Check if db-connection is ready. |
||
| 301 | * |
||
| 302 | * @return boolean |
||
| 303 | */ |
||
| 304 | 45 | public function isReady() |
|
| 305 | { |
||
| 306 | 45 | return $this->connected ? true : false; |
|
| 307 | } |
||
| 308 | |||
| 309 | /** |
||
| 310 | * Get a new "Prepare"-Object for your sql-query. |
||
| 311 | * |
||
| 312 | * @param string $query |
||
| 313 | * |
||
| 314 | * @return Prepare |
||
| 315 | */ |
||
| 316 | 2 | public function prepare($query) |
|
| 317 | { |
||
| 318 | 2 | return new Prepare($this, $query); |
|
| 319 | } |
||
| 320 | |||
| 321 | /** |
||
| 322 | * Execute a sql-query and return the result-array for select-statements. |
||
| 323 | * |
||
| 324 | * @param $query |
||
| 325 | * |
||
| 326 | * @return mixed |
||
| 327 | * @deprecated |
||
| 328 | * @throws \Exception |
||
| 329 | */ |
||
| 330 | public static function qry($query) |
||
| 355 | |||
| 356 | /** |
||
| 357 | * getInstance() |
||
| 358 | * |
||
| 359 | * @param string $hostname |
||
| 360 | * @param string $username |
||
| 361 | * @param string $password |
||
| 362 | * @param string $database |
||
| 363 | * @param string $port default is (int)3306 |
||
| 364 | * @param string $charset default is 'utf8' or 'utf8mb4' (if supported) |
||
| 365 | * @param bool|string $exit_on_error use a empty string "" or false to disable it |
||
| 366 | * @param bool|string $echo_on_error use a empty string "" or false to disable it |
||
| 367 | * @param string $logger_class_name |
||
| 368 | * @param string $logger_level |
||
| 369 | * @param bool|string $session_to_db use a empty string "" or false to disable it |
||
| 370 | * |
||
| 371 | * @return \voku\db\DB |
||
| 372 | */ |
||
| 373 | 57 | public static function getInstance($hostname = '', $username = '', $password = '', $database = '', $port = '', $charset = '', $exit_on_error = '', $echo_on_error = '', $logger_class_name = '', $logger_level = '', $session_to_db = '') |
|
| 419 | |||
| 420 | /** |
||
| 421 | * Execute a sql-query. |
||
| 422 | * |
||
| 423 | * @param string $sql sql-query |
||
| 424 | * |
||
| 425 | * @param array|boolean $params "array" of sql-query-parameters |
||
| 426 | * "false" if you don't need any parameter (default) |
||
| 427 | * |
||
| 428 | * @return bool|int|Result "Result" by "<b>SELECT</b>"-queries<br /> |
||
| 429 | * "int" (insert_id) by "<b>INSERT / REPLACE</b>"-queries<br /> |
||
| 430 | * "int" (affected_rows) by "<b>UPDATE / DELETE</b>"-queries<br /> |
||
| 431 | * "true" by e.g. "DROP"-queries<br /> |
||
| 432 | * "false" on error |
||
| 433 | * |
||
| 434 | * @throws \Exception |
||
| 435 | */ |
||
| 436 | 35 | public function query($sql = '', $params = false) |
|
| 510 | |||
| 511 | /** |
||
| 512 | * _parseQueryParams |
||
| 513 | * |
||
| 514 | * @param string $sql |
||
| 515 | * @param array $params |
||
| 516 | * |
||
| 517 | * @return string |
||
| 518 | */ |
||
| 519 | 3 | private function _parseQueryParams($sql, array $params) |
|
| 540 | |||
| 541 | /** |
||
| 542 | * Try to secure a variable, so can you use it in sql-queries. |
||
| 543 | * |
||
| 544 | * <p> |
||
| 545 | * <strong>int:</strong> (also strings that contains only an int-value)<br /> |
||
| 546 | * 1. parse into "int" |
||
| 547 | * </p><br /> |
||
| 548 | * |
||
| 549 | * <p> |
||
| 550 | * <strong>float:</strong><br /> |
||
| 551 | * 1. return "float" |
||
| 552 | * </p><br /> |
||
| 553 | * |
||
| 554 | * <p> |
||
| 555 | * <strong>string:</strong><br /> |
||
| 556 | * 1. check if the string isn't a default mysql-time-function e.g. 'CURDATE()'<br /> |
||
| 557 | * 2. trim whitespace<br /> |
||
| 558 | * 3. trim '<br /> |
||
| 559 | * 4. escape the string (and remove non utf-8 chars)<br /> |
||
| 560 | * 5. trim ' again (because we maybe removed some chars)<br /> |
||
| 561 | * 6. add ' around the new string<br /> |
||
| 562 | * </p><br /> |
||
| 563 | * |
||
| 564 | * <p> |
||
| 565 | * <strong>array:</strong><br /> |
||
| 566 | * 1. return null |
||
| 567 | * </p><br /> |
||
| 568 | * |
||
| 569 | * <p> |
||
| 570 | * <strong>object:</strong><br /> |
||
| 571 | * 1. return false |
||
| 572 | * </p><br /> |
||
| 573 | * |
||
| 574 | * <p> |
||
| 575 | * <strong>null:</strong><br /> |
||
| 576 | * 1. return null |
||
| 577 | * </p> |
||
| 578 | * |
||
| 579 | * @param mixed $var |
||
| 580 | * |
||
| 581 | * @return mixed |
||
| 582 | */ |
||
| 583 | 26 | public function secure($var) |
|
| 609 | |||
| 610 | /** |
||
| 611 | * Escape: Use "mysqli_real_escape_string" and clean non UTF-8 chars + some extra optional stuff. |
||
| 612 | * |
||
| 613 | * @param mixed $var boolean: convert into "integer"<br /> |
||
| 614 | * int: int (don't change it)<br /> |
||
| 615 | * float: float (don't change it)<br /> |
||
| 616 | * null: null (don't change it)<br /> |
||
| 617 | * array: run escape() for every key => value<br /> |
||
| 618 | * string: run UTF8::cleanup() and mysqli_real_escape_string()<br /> |
||
| 619 | * @param bool $stripe_non_utf8 |
||
| 620 | * @param bool $html_entity_decode |
||
| 621 | * @param bool|null $convert_array <strong>false</strong> => Keep the array.<br /> |
||
| 622 | * <strong>true</strong> => Convert to string var1,var2,var3...<br /> |
||
| 623 | * <strong>null</strong> => Convert the array into null, every time. |
||
| 624 | * |
||
| 625 | * @return mixed |
||
| 626 | */ |
||
| 627 | 33 | public function escape($var = '', $stripe_non_utf8 = true, $html_entity_decode = false, $convert_array = false) |
|
| 741 | |||
| 742 | /** |
||
| 743 | * Get the mysqli-link (link identifier returned by mysqli-connect). |
||
| 744 | * |
||
| 745 | * @return \mysqli |
||
| 746 | */ |
||
| 747 | 35 | public function getLink() |
|
| 751 | |||
| 752 | /** |
||
| 753 | * Returns the auto generated id used in the last query. |
||
| 754 | * |
||
| 755 | * @return int|string |
||
| 756 | */ |
||
| 757 | 22 | public function insert_id() |
|
| 761 | |||
| 762 | /** |
||
| 763 | * Gets the number of affected rows in a previous MySQL operation. |
||
| 764 | * |
||
| 765 | * @return int |
||
| 766 | */ |
||
| 767 | 8 | public function affected_rows() |
|
| 771 | |||
| 772 | /** |
||
| 773 | * Error-handling for the sql-query. |
||
| 774 | * |
||
| 775 | * @param string $errorMsg |
||
| 776 | * @param string $sql |
||
| 777 | * @param array|bool $sqlParams false if there wasn't any parameter |
||
| 778 | * |
||
| 779 | * @throws \Exception |
||
| 780 | * |
||
| 781 | * @return bool |
||
| 782 | */ |
||
| 783 | 9 | View Code Duplication | protected function queryErrorHandling($errorMsg, $sql, $sqlParams = false) |
| 811 | |||
| 812 | /** |
||
| 813 | * Reconnect to the MySQL-Server. |
||
| 814 | * |
||
| 815 | * @param bool $checkViaPing |
||
| 816 | * |
||
| 817 | * @return bool |
||
| 818 | */ |
||
| 819 | 3 | public function reconnect($checkViaPing = false) |
|
| 834 | |||
| 835 | /** |
||
| 836 | * Pings a server connection, or tries to reconnect |
||
| 837 | * if the connection has gone down. |
||
| 838 | * |
||
| 839 | * @return boolean |
||
| 840 | */ |
||
| 841 | 3 | public function ping() |
|
| 855 | |||
| 856 | /** |
||
| 857 | * Execute select/insert/update/delete sql-queries. |
||
| 858 | * |
||
| 859 | * @param string $query sql-query |
||
| 860 | * @param bool $useCache use cache? |
||
| 861 | * @param int $cacheTTL cache-ttl in seconds |
||
| 862 | * |
||
| 863 | * @return mixed "array" by "<b>SELECT</b>"-queries<br /> |
||
| 864 | * "int" (insert_id) by "<b>INSERT</b>"-queries<br /> |
||
| 865 | * "int" (affected_rows) by "<b>UPDATE / DELETE</b>"-queries<br /> |
||
| 866 | * "true" by e.g. "DROP"-queries<br /> |
||
| 867 | * "false" on error |
||
| 868 | */ |
||
| 869 | 3 | public static function execSQL($query, $useCache = false, $cacheTTL = 3600) |
|
| 916 | |||
| 917 | /** |
||
| 918 | * Get the current charset. |
||
| 919 | * |
||
| 920 | * @return string |
||
| 921 | */ |
||
| 922 | 1 | public function get_charset() |
|
| 926 | |||
| 927 | /** |
||
| 928 | * Enables or disables internal report functions |
||
| 929 | * |
||
| 930 | * @link http://php.net/manual/en/function.mysqli-report.php |
||
| 931 | * |
||
| 932 | * @param int $flags <p> |
||
| 933 | * <table> |
||
| 934 | * Supported flags |
||
| 935 | * <tr valign="top"> |
||
| 936 | * <td>Name</td> |
||
| 937 | * <td>Description</td> |
||
| 938 | * </tr> |
||
| 939 | * <tr valign="top"> |
||
| 940 | * <td><b>MYSQLI_REPORT_OFF</b></td> |
||
| 941 | * <td>Turns reporting off</td> |
||
| 942 | * </tr> |
||
| 943 | * <tr valign="top"> |
||
| 944 | * <td><b>MYSQLI_REPORT_ERROR</b></td> |
||
| 945 | * <td>Report errors from mysqli function calls</td> |
||
| 946 | * </tr> |
||
| 947 | * <tr valign="top"> |
||
| 948 | * <td><b>MYSQLI_REPORT_STRICT</b></td> |
||
| 949 | * <td> |
||
| 950 | * Throw <b>mysqli_sql_exception</b> for errors |
||
| 951 | * instead of warnings |
||
| 952 | * </td> |
||
| 953 | * </tr> |
||
| 954 | * <tr valign="top"> |
||
| 955 | * <td><b>MYSQLI_REPORT_INDEX</b></td> |
||
| 956 | * <td>Report if no index or bad index was used in a query</td> |
||
| 957 | * </tr> |
||
| 958 | * <tr valign="top"> |
||
| 959 | * <td><b>MYSQLI_REPORT_ALL</b></td> |
||
| 960 | * <td>Set all options (report all)</td> |
||
| 961 | * </tr> |
||
| 962 | * </table> |
||
| 963 | * </p> |
||
| 964 | * |
||
| 965 | * @return bool |
||
| 966 | */ |
||
| 967 | public function set_mysqli_report($flags) |
||
| 971 | |||
| 972 | /** |
||
| 973 | * Set the current charset. |
||
| 974 | * |
||
| 975 | * @param string $charset |
||
| 976 | * |
||
| 977 | * @return bool |
||
| 978 | */ |
||
| 979 | 7 | public function set_charset($charset) |
|
| 1001 | |||
| 1002 | /** |
||
| 1003 | * Set the option to convert null to "''" (empty string). |
||
| 1004 | * |
||
| 1005 | * Used in secure() => select(), insert(), update(), delete() |
||
| 1006 | * |
||
| 1007 | * @param $bool |
||
| 1008 | */ |
||
| 1009 | 1 | public function set_convert_null_to_empty_string($bool) |
|
| 1013 | |||
| 1014 | /** |
||
| 1015 | * Get all table-names via "SHOW TABLES". |
||
| 1016 | * |
||
| 1017 | * @return array |
||
| 1018 | */ |
||
| 1019 | 1 | public function getAllTables() |
|
| 1026 | |||
| 1027 | /** |
||
| 1028 | * Execute a sql-multi-query. |
||
| 1029 | * |
||
| 1030 | * @param string $sql |
||
| 1031 | * |
||
| 1032 | * @return false|Result[] "Result"-Array by "<b>SELECT</b>"-queries<br /> |
||
| 1033 | * "boolean" by only "<b>INSERT</b>"-queries<br /> |
||
| 1034 | * "boolean" by only (affected_rows) by "<b>UPDATE / DELETE</b>"-queries<br /> |
||
| 1035 | * "boolean" by only by e.g. "DROP"-queries<br /> |
||
| 1036 | * |
||
| 1037 | * @throws \Exception |
||
| 1038 | */ |
||
| 1039 | 1 | public function multi_query($sql) |
|
| 1101 | |||
| 1102 | /** |
||
| 1103 | * alias: "beginTransaction()" |
||
| 1104 | */ |
||
| 1105 | 1 | public function startTransaction() |
|
| 1109 | |||
| 1110 | /** |
||
| 1111 | * Begins a transaction, by turning off auto commit. |
||
| 1112 | * |
||
| 1113 | * @return boolean this will return true or false indicating success of transaction |
||
| 1114 | */ |
||
| 1115 | 4 | public function beginTransaction() |
|
| 1136 | |||
| 1137 | /** |
||
| 1138 | * Clear the errors in "_debug->_errors". |
||
| 1139 | * |
||
| 1140 | * @return bool |
||
| 1141 | */ |
||
| 1142 | 4 | public function clearErrors() |
|
| 1146 | |||
| 1147 | /** |
||
| 1148 | * Check if we are in a transaction. |
||
| 1149 | * |
||
| 1150 | * @return boolean |
||
| 1151 | */ |
||
| 1152 | 4 | public function inTransaction() |
|
| 1156 | |||
| 1157 | /** |
||
| 1158 | * Ends a transaction and commits if no errors, then ends autocommit. |
||
| 1159 | * |
||
| 1160 | * @return boolean this will return true or false indicating success of transactions |
||
| 1161 | */ |
||
| 1162 | 2 | public function endTransaction() |
|
| 1178 | |||
| 1179 | /** |
||
| 1180 | * Get all errors from "$this->_errors". |
||
| 1181 | * |
||
| 1182 | * @return array|false false === on errors |
||
| 1183 | */ |
||
| 1184 | 2 | public function errors() |
|
| 1190 | |||
| 1191 | /** |
||
| 1192 | * Rollback in a transaction. |
||
| 1193 | */ |
||
| 1194 | 2 | public function rollback() |
|
| 1207 | |||
| 1208 | /** |
||
| 1209 | * Execute a "insert"-query. |
||
| 1210 | * |
||
| 1211 | * @param string $table |
||
| 1212 | * @param array $data |
||
| 1213 | * @param string|null $databaseName <p>use <strong>null</strong> if you will use the current database</p> |
||
| 1214 | * |
||
| 1215 | * @return false|int false on error |
||
| 1216 | */ |
||
| 1217 | 21 | public function insert($table, array $data = array(), $databaseName = null) |
|
| 1244 | |||
| 1245 | /** |
||
| 1246 | * Parses arrays with value pairs and generates SQL to use in queries. |
||
| 1247 | * |
||
| 1248 | * @param array $arrayPair |
||
| 1249 | * @param string $glue this is the separator |
||
| 1250 | * |
||
| 1251 | * @return string |
||
| 1252 | * |
||
| 1253 | * @internal |
||
| 1254 | */ |
||
| 1255 | 23 | public function _parseArrayPair($arrayPair, $glue = ',') |
|
| 1401 | |||
| 1402 | /** |
||
| 1403 | * Quote && Escape e.g. a table name string. |
||
| 1404 | * |
||
| 1405 | * @param string $str |
||
| 1406 | * |
||
| 1407 | * @return string |
||
| 1408 | */ |
||
| 1409 | 26 | public function quote_string($str) |
|
| 1422 | |||
| 1423 | /** |
||
| 1424 | * Get errors from "$this->_errors". |
||
| 1425 | * |
||
| 1426 | * @return array |
||
| 1427 | */ |
||
| 1428 | 1 | public function getErrors() |
|
| 1432 | |||
| 1433 | /** |
||
| 1434 | * Execute a "replace"-query. |
||
| 1435 | * |
||
| 1436 | * @param string $table |
||
| 1437 | * @param array $data |
||
| 1438 | * @param null|string $databaseName <p>use <strong>null</strong> if you will use the current database</p> |
||
| 1439 | * |
||
| 1440 | * @return false|int false on error |
||
| 1441 | */ |
||
| 1442 | 1 | public function replace($table, array $data = array(), $databaseName = null) |
|
| 1483 | |||
| 1484 | /** |
||
| 1485 | * Execute a "update"-query. |
||
| 1486 | * |
||
| 1487 | * @param string $table |
||
| 1488 | * @param array $data |
||
| 1489 | * @param array|string $where |
||
| 1490 | * @param null|string $databaseName <p>use <strong>null</strong> if you will use the current database</p> |
||
| 1491 | * |
||
| 1492 | * @return false|int false on error |
||
| 1493 | */ |
||
| 1494 | 6 | public function update($table, array $data = array(), $where = '1=1', $databaseName = null) |
|
| 1529 | |||
| 1530 | /** |
||
| 1531 | * Execute a "delete"-query. |
||
| 1532 | * |
||
| 1533 | * @param string $table |
||
| 1534 | * @param string|array $where |
||
| 1535 | * @param string|null $databaseName <p>use <strong>null</strong> if you will use the current database</p> |
||
| 1536 | * |
||
| 1537 | * @return false|int false on error |
||
| 1538 | */ |
||
| 1539 | 2 | public function delete($table, $where, $databaseName = null) |
|
| 1566 | |||
| 1567 | /** |
||
| 1568 | * Execute a "select"-query. |
||
| 1569 | * |
||
| 1570 | * @param string $table |
||
| 1571 | * @param string|array $where |
||
| 1572 | * @param string|null $databaseName <p>use <strong>null</strong> if you will use the current database</p> |
||
| 1573 | * |
||
| 1574 | * @return false|Result false on error |
||
| 1575 | */ |
||
| 1576 | 20 | public function select($table, $where = '1=1', $databaseName = null) |
|
| 1603 | |||
| 1604 | /** |
||
| 1605 | * Get the last sql-error. |
||
| 1606 | * |
||
| 1607 | * @return string false on error |
||
| 1608 | */ |
||
| 1609 | 1 | public function lastError() |
|
| 1615 | |||
| 1616 | /** |
||
| 1617 | * @return Debug |
||
| 1618 | */ |
||
| 1619 | 9 | public function getDebugger() |
|
| 1623 | |||
| 1624 | /** |
||
| 1625 | * __destruct |
||
| 1626 | * |
||
| 1627 | */ |
||
| 1628 | public function __destruct() |
||
| 1635 | |||
| 1636 | /** |
||
| 1637 | * Closes a previously opened database connection. |
||
| 1638 | */ |
||
| 1639 | 2 | public function close() |
|
| 1647 | |||
| 1648 | /** |
||
| 1649 | * Prevent the instance from being cloned. |
||
| 1650 | * |
||
| 1651 | * @return void |
||
| 1652 | */ |
||
| 1653 | private function __clone() |
||
| 1656 | |||
| 1657 | /** |
||
| 1658 | * __wakeup |
||
| 1659 | * |
||
| 1660 | * @return void |
||
| 1661 | */ |
||
| 1662 | 2 | public function __wakeup() |
|
| 1666 | |||
| 1667 | } |
||
| 1668 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..