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 DatabaseConnection 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 DatabaseConnection, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 48 | class DatabaseConnection |
||
| 49 | { |
||
| 50 | /** |
||
| 51 | * The AND constraint in where clause |
||
| 52 | * |
||
| 53 | * @var string |
||
| 54 | */ |
||
| 55 | const AND_Constraint = 'AND'; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * The OR constraint in where clause |
||
| 59 | * |
||
| 60 | * @var string |
||
| 61 | */ |
||
| 62 | const OR_Constraint = 'OR'; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Set "TRUE" or "1" if you want database errors outputted. Set to "2" if you also want successful database actions outputted. |
||
| 66 | * |
||
| 67 | * @var bool|int |
||
| 68 | */ |
||
| 69 | public $debugOutput = false; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * Internally: Set to last built query (not necessarily executed...) |
||
| 73 | * |
||
| 74 | * @var string |
||
| 75 | */ |
||
| 76 | public $debug_lastBuiltQuery = ''; |
||
| 77 | |||
| 78 | /** |
||
| 79 | * Set "TRUE" if you want the last built query to be stored in $debug_lastBuiltQuery independent of $this->debugOutput |
||
| 80 | * |
||
| 81 | * @var bool |
||
| 82 | */ |
||
| 83 | public $store_lastBuiltQuery = false; |
||
| 84 | |||
| 85 | /** |
||
| 86 | * Set this to 1 to get queries explained (devIPmask must match). Set the value to 2 to the same but disregarding the devIPmask. |
||
| 87 | * There is an alternative option to enable explain output in the admin panel under "TypoScript", which will produce much nicer output, but only works in FE. |
||
| 88 | * |
||
| 89 | * @var bool |
||
| 90 | */ |
||
| 91 | public $explainOutput = 0; |
||
| 92 | |||
| 93 | /** |
||
| 94 | * @var string Database host to connect to |
||
| 95 | */ |
||
| 96 | protected $databaseHost = ''; |
||
| 97 | |||
| 98 | /** |
||
| 99 | * @var int Database port to connect to |
||
| 100 | */ |
||
| 101 | protected $databasePort = 3306; |
||
| 102 | |||
| 103 | /** |
||
| 104 | * @var string|NULL Database socket to connect to |
||
| 105 | */ |
||
| 106 | protected $databaseSocket = null; |
||
| 107 | |||
| 108 | /** |
||
| 109 | * @var string Database name to connect to |
||
| 110 | */ |
||
| 111 | protected $databaseName = ''; |
||
| 112 | |||
| 113 | /** |
||
| 114 | * @var string Database user to connect with |
||
| 115 | */ |
||
| 116 | protected $databaseUsername = ''; |
||
| 117 | |||
| 118 | /** |
||
| 119 | * @var string Database password to connect with |
||
| 120 | */ |
||
| 121 | protected $databaseUserPassword = ''; |
||
| 122 | |||
| 123 | /** |
||
| 124 | * @var bool TRUE if database connection should be persistent |
||
| 125 | * @see http://php.net/manual/de/mysqli.persistconns.php |
||
| 126 | */ |
||
| 127 | protected $persistentDatabaseConnection = false; |
||
| 128 | |||
| 129 | /** |
||
| 130 | * @var bool TRUE if connection between client and sql server is compressed |
||
| 131 | */ |
||
| 132 | protected $connectionCompression = false; |
||
| 133 | |||
| 134 | /** |
||
| 135 | * The charset for the connection; will be passed on to |
||
| 136 | * mysqli_set_charset during connection initialization. |
||
| 137 | * |
||
| 138 | * @var string |
||
| 139 | */ |
||
| 140 | protected $connectionCharset = 'utf8'; |
||
| 141 | |||
| 142 | /** |
||
| 143 | * @var array List of commands executed after connection was established |
||
| 144 | */ |
||
| 145 | protected $initializeCommandsAfterConnect = []; |
||
| 146 | |||
| 147 | /** |
||
| 148 | * @var bool TRUE if database connection is established |
||
| 149 | */ |
||
| 150 | protected $isConnected = false; |
||
| 151 | |||
| 152 | /** |
||
| 153 | * @var \mysqli $link Default database link object |
||
| 154 | */ |
||
| 155 | protected $link = null; |
||
| 156 | |||
| 157 | /** |
||
| 158 | * Default character set, applies unless character set or collation are explicitly set |
||
| 159 | * |
||
| 160 | * @var string |
||
| 161 | */ |
||
| 162 | public $default_charset = 'utf8'; |
||
| 163 | |||
| 164 | /** |
||
| 165 | * @var array<PostProcessQueryHookInterface> |
||
| 166 | */ |
||
| 167 | protected $preProcessHookObjects = []; |
||
| 168 | |||
| 169 | /** |
||
| 170 | * @var array<PreProcessQueryHookInterface> |
||
| 171 | */ |
||
| 172 | protected $postProcessHookObjects = []; |
||
| 173 | |||
| 174 | /** |
||
| 175 | * Internal property to mark if a deprecation log warning has been thrown in this request |
||
| 176 | * in order to avoid a load of deprecation. |
||
| 177 | * @var bool |
||
| 178 | */ |
||
| 179 | protected $deprecationWarningThrown = false; |
||
| 180 | |||
| 181 | /** |
||
| 182 | * Initialize the database connection |
||
| 183 | */ |
||
| 184 | public function initialize() |
||
| 188 | |||
| 189 | /************************************ |
||
| 190 | * |
||
| 191 | * Query execution |
||
| 192 | * |
||
| 193 | * These functions are the RECOMMENDED DBAL functions for use in your applications |
||
| 194 | * Using these functions will allow the DBAL to use alternative ways of accessing data (contrary to if a query is returned!) |
||
| 195 | * They compile a query AND execute it immediately and then return the result |
||
| 196 | * This principle heightens our ability to create various forms of DBAL of the functions. |
||
| 197 | * Generally: We want to return a result pointer/object, never queries. |
||
| 198 | * Also, having the table name together with the actual query execution allows us to direct the request to other databases. |
||
| 199 | * |
||
| 200 | **************************************/ |
||
| 201 | |||
| 202 | /** |
||
| 203 | * Creates and executes an INSERT SQL-statement for $table from the array with field/value pairs $fields_values. |
||
| 204 | * Using this function specifically allows us to handle BLOB and CLOB fields depending on DB |
||
| 205 | * |
||
| 206 | * @param string $table Table name |
||
| 207 | * @param array $fields_values Field values as key=>value pairs. Values will be escaped internally. Typically you would fill an array like "$insertFields" with 'fieldname'=>'value' and pass it to this function as argument. |
||
| 208 | * @param bool|array|string $no_quote_fields See fullQuoteArray() |
||
| 209 | * @return bool|\mysqli_result|object MySQLi result object / DBAL object |
||
| 210 | */ |
||
| 211 | View Code Duplication | public function exec_INSERTquery($table, $fields_values, $no_quote_fields = false) |
|
| 224 | |||
| 225 | /** |
||
| 226 | * Creates and executes an INSERT SQL-statement for $table with multiple rows. |
||
| 227 | * |
||
| 228 | * @param string $table Table name |
||
| 229 | * @param array $fields Field names |
||
| 230 | * @param array $rows Table rows. Each row should be an array with field values mapping to $fields |
||
| 231 | * @param bool|array|string $no_quote_fields See fullQuoteArray() |
||
| 232 | * @return bool|\mysqli_result|object MySQLi result object / DBAL object |
||
| 233 | */ |
||
| 234 | View Code Duplication | public function exec_INSERTmultipleRows($table, array $fields, array $rows, $no_quote_fields = false) |
|
| 247 | |||
| 248 | /** |
||
| 249 | * Creates and executes an UPDATE SQL-statement for $table where $where-clause (typ. 'uid=...') from the array with field/value pairs $fields_values. |
||
| 250 | * Using this function specifically allow us to handle BLOB and CLOB fields depending on DB |
||
| 251 | * |
||
| 252 | * @param string $table Database tablename |
||
| 253 | * @param string $where WHERE clause, eg. "uid=1". NOTICE: You must escape values in this argument with $this->fullQuoteStr() yourself! |
||
| 254 | * @param array $fields_values Field values as key=>value pairs. Values will be escaped internally. Typically you would fill an array like "$updateFields" with 'fieldname'=>'value' and pass it to this function as argument. |
||
| 255 | * @param bool|array|string $no_quote_fields See fullQuoteArray() |
||
| 256 | * @return bool|\mysqli_result|object MySQLi result object / DBAL object |
||
| 257 | */ |
||
| 258 | View Code Duplication | public function exec_UPDATEquery($table, $where, $fields_values, $no_quote_fields = false) |
|
| 271 | |||
| 272 | /** |
||
| 273 | * Creates and executes a DELETE SQL-statement for $table where $where-clause |
||
| 274 | * |
||
| 275 | * @param string $table Database tablename |
||
| 276 | * @param string $where WHERE clause, eg. "uid=1". NOTICE: You must escape values in this argument with $this->fullQuoteStr() yourself! |
||
| 277 | * @return bool|\mysqli_result|object MySQLi result object / DBAL object |
||
| 278 | */ |
||
| 279 | View Code Duplication | public function exec_DELETEquery($table, $where) |
|
| 292 | |||
| 293 | /** |
||
| 294 | * Creates and executes a SELECT SQL-statement |
||
| 295 | * Using this function specifically allow us to handle the LIMIT feature independently of DB. |
||
| 296 | * |
||
| 297 | * @param string $select_fields List of fields to select from the table. This is what comes right after "SELECT ...". Required value. |
||
| 298 | * @param string $from_table Table(s) from which to select. This is what comes right after "FROM ...". Required value. |
||
| 299 | * @param string $where_clause Additional WHERE clauses put in the end of the query. NOTICE: You must escape values in this argument with $this->fullQuoteStr() yourself! DO NOT PUT IN GROUP BY, ORDER BY or LIMIT! |
||
| 300 | * @param string $groupBy Optional GROUP BY field(s), if none, supply blank string. |
||
| 301 | * @param string $orderBy Optional ORDER BY field(s), if none, supply blank string. |
||
| 302 | * @param string $limit Optional LIMIT value ([begin,]max), if none, supply blank string. |
||
| 303 | * @return bool|\mysqli_result|object MySQLi result object / DBAL object |
||
| 304 | */ |
||
| 305 | public function exec_SELECTquery($select_fields, $from_table, $where_clause, $groupBy = '', $orderBy = '', $limit = '') |
||
| 322 | |||
| 323 | /** |
||
| 324 | * Creates and executes a SELECT query, selecting fields ($select) from two/three tables joined |
||
| 325 | * Use $mm_table together with $local_table or $foreign_table to select over two tables. Or use all three tables to select the full MM-relation. |
||
| 326 | * The JOIN is done with [$local_table].uid <--> [$mm_table].uid_local / [$mm_table].uid_foreign <--> [$foreign_table].uid |
||
| 327 | * The function is very useful for selecting MM-relations between tables adhering to the MM-format used by TCE (TYPO3 Core Engine). See the section on $GLOBALS['TCA'] in Inside TYPO3 for more details. |
||
| 328 | * |
||
| 329 | * @param string $select Field list for SELECT |
||
| 330 | * @param string $local_table Tablename, local table |
||
| 331 | * @param string $mm_table Tablename, relation table |
||
| 332 | * @param string $foreign_table Tablename, foreign table |
||
| 333 | * @param string $whereClause Optional additional WHERE clauses put in the end of the query. NOTICE: You must escape values in this argument with $this->fullQuoteStr() yourself! DO NOT PUT IN GROUP BY, ORDER BY or LIMIT! You have to prepend 'AND ' to this parameter yourself! |
||
| 334 | * @param string $groupBy Optional GROUP BY field(s), if none, supply blank string. |
||
| 335 | * @param string $orderBy Optional ORDER BY field(s), if none, supply blank string. |
||
| 336 | * @param string $limit Optional LIMIT value ([begin,]max), if none, supply blank string. |
||
| 337 | * @return bool|\mysqli_result|object MySQLi result object / DBAL object |
||
| 338 | * @see exec_SELECTquery() |
||
| 339 | */ |
||
| 340 | public function exec_SELECT_mm_query($select, $local_table, $mm_table, $foreign_table, $whereClause = '', $groupBy = '', $orderBy = '', $limit = '') |
||
| 346 | |||
| 347 | /** |
||
| 348 | * Executes a select based on input query parts array |
||
| 349 | * |
||
| 350 | * @param array $queryParts Query parts array |
||
| 351 | * @return bool|\mysqli_result|object MySQLi result object / DBAL object |
||
| 352 | * @see exec_SELECTquery() |
||
| 353 | */ |
||
| 354 | public function exec_SELECT_queryArray($queryParts) |
||
| 359 | |||
| 360 | /** |
||
| 361 | * Creates and executes a SELECT SQL-statement AND traverse result set and returns array with records in. |
||
| 362 | * |
||
| 363 | * @param string $select_fields List of fields to select from the table. This is what comes right after "SELECT ...". Required value. |
||
| 364 | * @param string $from_table Table(s) from which to select. This is what comes right after "FROM ...". Required value. |
||
| 365 | * @param string $where_clause Additional WHERE clauses put in the end of the query. NOTICE: You must escape values in this argument with $this->fullQuoteStr() yourself! DO NOT PUT IN GROUP BY, ORDER BY or LIMIT! |
||
| 366 | * @param string $groupBy Optional GROUP BY field(s), if none, supply blank string. |
||
| 367 | * @param string $orderBy Optional ORDER BY field(s), if none, supply blank string. |
||
| 368 | * @param string $limit Optional LIMIT value ([begin,]max), if none, supply blank string. |
||
| 369 | * @param string $uidIndexField If set, the result array will carry this field names value as index. Requires that field to be selected of course! |
||
| 370 | * @return array|NULL Array of rows, or NULL in case of SQL error |
||
| 371 | * @see exec_SELECTquery() |
||
| 372 | * @throws \InvalidArgumentException |
||
| 373 | */ |
||
| 374 | public function exec_SELECTgetRows($select_fields, $from_table, $where_clause, $groupBy = '', $orderBy = '', $limit = '', $uidIndexField = '') |
||
| 401 | |||
| 402 | /** |
||
| 403 | * Creates and executes a SELECT SQL-statement AND gets a result set and returns an array with a single record in. |
||
| 404 | * LIMIT is automatically set to 1 and can not be overridden. |
||
| 405 | * |
||
| 406 | * @param string $select_fields List of fields to select from the table. |
||
| 407 | * @param string $from_table Table(s) from which to select. |
||
| 408 | * @param string $where_clause Optional additional WHERE clauses put in the end of the query. NOTICE: You must escape values in this argument with $this->fullQuoteStr() yourself! |
||
| 409 | * @param string $groupBy Optional GROUP BY field(s), if none, supply blank string. |
||
| 410 | * @param string $orderBy Optional ORDER BY field(s), if none, supply blank string. |
||
| 411 | * @param bool $numIndex If set, the result will be fetched with sql_fetch_row, otherwise sql_fetch_assoc will be used. |
||
| 412 | * @return array|FALSE|NULL Single row, FALSE on empty result, NULL on error |
||
| 413 | */ |
||
| 414 | public function exec_SELECTgetSingleRow($select_fields, $from_table, $where_clause, $groupBy = '', $orderBy = '', $numIndex = false) |
||
| 429 | |||
| 430 | /** |
||
| 431 | * Counts the number of rows in a table. |
||
| 432 | * |
||
| 433 | * @param string $field Name of the field to use in the COUNT() expression (e.g. '*') |
||
| 434 | * @param string $table Name of the table to count rows for |
||
| 435 | * @param string $where (optional) WHERE statement of the query |
||
| 436 | * @return mixed Number of rows counter (int) or FALSE if something went wrong (bool) |
||
| 437 | */ |
||
| 438 | public function exec_SELECTcountRows($field, $table, $where = '1=1') |
||
| 450 | |||
| 451 | /** |
||
| 452 | * Truncates a table. |
||
| 453 | * |
||
| 454 | * @param string $table Database tablename |
||
| 455 | * @return mixed Result from handler |
||
| 456 | */ |
||
| 457 | View Code Duplication | public function exec_TRUNCATEquery($table) |
|
| 470 | |||
| 471 | /** |
||
| 472 | * Central query method. Also checks if there is a database connection. |
||
| 473 | * Use this to execute database queries instead of directly calling $this->link->query() |
||
| 474 | * |
||
| 475 | * @param string $query The query to send to the database |
||
| 476 | * @return bool|\mysqli_result |
||
| 477 | */ |
||
| 478 | protected function query($query) |
||
| 486 | |||
| 487 | /************************************** |
||
| 488 | * |
||
| 489 | * Query building |
||
| 490 | * |
||
| 491 | **************************************/ |
||
| 492 | /** |
||
| 493 | * Creates an INSERT SQL-statement for $table from the array with field/value pairs $fields_values. |
||
| 494 | * |
||
| 495 | * @param string $table See exec_INSERTquery() |
||
| 496 | * @param array $fields_values See exec_INSERTquery() |
||
| 497 | * @param bool|array|string $no_quote_fields See fullQuoteArray() |
||
| 498 | * @return string|NULL Full SQL query for INSERT, NULL if $fields_values is empty |
||
| 499 | */ |
||
| 500 | public function INSERTquery($table, $fields_values, $no_quote_fields = false) |
||
| 521 | |||
| 522 | /** |
||
| 523 | * Creates an INSERT SQL-statement for $table with multiple rows. |
||
| 524 | * |
||
| 525 | * @param string $table Table name |
||
| 526 | * @param array $fields Field names |
||
| 527 | * @param array $rows Table rows. Each row should be an array with field values mapping to $fields |
||
| 528 | * @param bool|array|string $no_quote_fields See fullQuoteArray() |
||
| 529 | * @return string|NULL Full SQL query for INSERT, NULL if $rows is empty |
||
| 530 | */ |
||
| 531 | public function INSERTmultipleRows($table, array $fields, array $rows, $no_quote_fields = false) |
||
| 558 | |||
| 559 | /** |
||
| 560 | * Creates an UPDATE SQL-statement for $table where $where-clause (typ. 'uid=...') from the array with field/value pairs $fields_values. |
||
| 561 | * |
||
| 562 | * |
||
| 563 | * @param string $table See exec_UPDATEquery() |
||
| 564 | * @param string $where See exec_UPDATEquery() |
||
| 565 | * @param array $fields_values See exec_UPDATEquery() |
||
| 566 | * @param bool|array|string $no_quote_fields See fullQuoteArray() |
||
| 567 | * @throws \InvalidArgumentException |
||
| 568 | * @return string Full SQL query for UPDATE |
||
| 569 | */ |
||
| 570 | public function UPDATEquery($table, $where, $fields_values, $no_quote_fields = false) |
||
| 598 | |||
| 599 | /** |
||
| 600 | * Creates a DELETE SQL-statement for $table where $where-clause |
||
| 601 | * |
||
| 602 | * @param string $table See exec_DELETEquery() |
||
| 603 | * @param string $where See exec_DELETEquery() |
||
| 604 | * @return string Full SQL query for DELETE |
||
| 605 | * @throws \InvalidArgumentException |
||
| 606 | */ |
||
| 607 | public function DELETEquery($table, $where) |
||
| 625 | |||
| 626 | /** |
||
| 627 | * Creates a SELECT SQL-statement |
||
| 628 | * |
||
| 629 | * @param string $select_fields See exec_SELECTquery() |
||
| 630 | * @param string $from_table See exec_SELECTquery() |
||
| 631 | * @param string $where_clause See exec_SELECTquery() |
||
| 632 | * @param string $groupBy See exec_SELECTquery() |
||
| 633 | * @param string $orderBy See exec_SELECTquery() |
||
| 634 | * @param string $limit See exec_SELECTquery() |
||
| 635 | * @return string Full SQL query for SELECT |
||
| 636 | */ |
||
| 637 | public function SELECTquery($select_fields, $from_table, $where_clause, $groupBy = '', $orderBy = '', $limit = '') |
||
| 659 | |||
| 660 | /** |
||
| 661 | * Creates a SELECT SQL-statement to be used as subquery within another query. |
||
| 662 | * BEWARE: This method should not be overridden within DBAL to prevent quoting from happening. |
||
| 663 | * |
||
| 664 | * @param string $select_fields List of fields to select from the table. |
||
| 665 | * @param string $from_table Table from which to select. |
||
| 666 | * @param string $where_clause Conditional WHERE statement |
||
| 667 | * @return string Full SQL query for SELECT |
||
| 668 | */ |
||
| 669 | public function SELECTsubquery($select_fields, $from_table, $where_clause) |
||
| 681 | |||
| 682 | /** |
||
| 683 | * Creates a SELECT query, selecting fields ($select) from two/three tables joined |
||
| 684 | * Use $mm_table together with $local_table or $foreign_table to select over two tables. Or use all three tables to select the full MM-relation. |
||
| 685 | * The JOIN is done with [$local_table].uid <--> [$mm_table].uid_local / [$mm_table].uid_foreign <--> [$foreign_table].uid |
||
| 686 | * The function is very useful for selecting MM-relations between tables adhering to the MM-format used by TCE (TYPO3 Core Engine). See the section on $GLOBALS['TCA'] in Inside TYPO3 for more details. |
||
| 687 | * |
||
| 688 | * @param string $select See exec_SELECT_mm_query() |
||
| 689 | * @param string $local_table See exec_SELECT_mm_query() |
||
| 690 | * @param string $mm_table See exec_SELECT_mm_query() |
||
| 691 | * @param string $foreign_table See exec_SELECT_mm_query() |
||
| 692 | * @param string $whereClause See exec_SELECT_mm_query() |
||
| 693 | * @param string $groupBy See exec_SELECT_mm_query() |
||
| 694 | * @param string $orderBy See exec_SELECT_mm_query() |
||
| 695 | * @param string $limit See exec_SELECT_mm_query() |
||
| 696 | * @return string Full SQL query for SELECT |
||
| 697 | * @see SELECTquery() |
||
| 698 | */ |
||
| 699 | public function SELECT_mm_query($select, $local_table, $mm_table, $foreign_table, $whereClause = '', $groupBy = '', $orderBy = '', $limit = '') |
||
| 705 | |||
| 706 | /** |
||
| 707 | * Creates a TRUNCATE TABLE SQL-statement |
||
| 708 | * |
||
| 709 | * @param string $table See exec_TRUNCATEquery() |
||
| 710 | * @return string Full SQL query for TRUNCATE TABLE |
||
| 711 | */ |
||
| 712 | public function TRUNCATEquery($table) |
||
| 728 | |||
| 729 | /** |
||
| 730 | * Returns a WHERE clause that can find a value ($value) in a list field ($field) |
||
| 731 | * For instance a record in the database might contain a list of numbers, |
||
| 732 | * "34,234,5" (with no spaces between). This query would be able to select that |
||
| 733 | * record based on the value "34", "234" or "5" regardless of their position in |
||
| 734 | * the list (left, middle or right). |
||
| 735 | * The value must not contain a comma (,) |
||
| 736 | * Is nice to look up list-relations to records or files in TYPO3 database tables. |
||
| 737 | * |
||
| 738 | * @param string $field Field name |
||
| 739 | * @param string $value Value to find in list |
||
| 740 | * @param string $table Table in which we are searching (for DBAL detection of quoteStr() method) |
||
| 741 | * @return string WHERE clause for a query |
||
| 742 | * @throws \InvalidArgumentException |
||
| 743 | */ |
||
| 744 | public function listQuery($field, $value, $table) |
||
| 755 | |||
| 756 | /** |
||
| 757 | * Returns a WHERE clause which will make an AND or OR search for the words in the $searchWords array in any of the fields in array $fields. |
||
| 758 | * |
||
| 759 | * @param array $searchWords Array of search words |
||
| 760 | * @param array $fields Array of fields |
||
| 761 | * @param string $table Table in which we are searching (for DBAL detection of quoteStr() method) |
||
| 762 | * @param string $constraint How multiple search words have to match ('AND' or 'OR') |
||
| 763 | * @return string WHERE clause for search |
||
| 764 | */ |
||
| 765 | public function searchQuery($searchWords, $fields, $table, $constraint = self::AND_Constraint) |
||
| 785 | |||
| 786 | /************************************** |
||
| 787 | * |
||
| 788 | * Prepared Query Support |
||
| 789 | * |
||
| 790 | **************************************/ |
||
| 791 | /** |
||
| 792 | * Creates a SELECT prepared SQL statement. |
||
| 793 | * |
||
| 794 | * @param string $select_fields See exec_SELECTquery() |
||
| 795 | * @param string $from_table See exec_SELECTquery() |
||
| 796 | * @param string $where_clause See exec_SELECTquery() |
||
| 797 | * @param string $groupBy See exec_SELECTquery() |
||
| 798 | * @param string $orderBy See exec_SELECTquery() |
||
| 799 | * @param string $limit See exec_SELECTquery() |
||
| 800 | * @param array $input_parameters An array of values with as many elements as there are bound parameters in the SQL statement being executed. All values are treated as \Fab\Vidi\Database\PreparedStatement::PARAM_AUTOTYPE. |
||
| 801 | * @return \Fab\Vidi\Database\PreparedStatement Prepared statement |
||
| 802 | */ |
||
| 803 | public function prepare_SELECTquery($select_fields, $from_table, $where_clause, $groupBy = '', $orderBy = '', $limit = '', array $input_parameters = []) |
||
| 816 | |||
| 817 | /** |
||
| 818 | * Creates a SELECT prepared SQL statement based on input query parts array |
||
| 819 | * |
||
| 820 | * @param array $queryParts Query parts array |
||
| 821 | * @param array $input_parameters An array of values with as many elements as there are bound parameters in the SQL statement being executed. All values are treated as \Fab\Vidi\Database\PreparedStatement::PARAM_AUTOTYPE. |
||
| 822 | * @return \Fab\Vidi\Database\PreparedStatement Prepared statement |
||
| 823 | */ |
||
| 824 | public function prepare_SELECTqueryArray(array $queryParts, array $input_parameters = []) |
||
| 829 | |||
| 830 | /** |
||
| 831 | * Prepares a prepared query. |
||
| 832 | * |
||
| 833 | * @param string $query The query to execute |
||
| 834 | * @param array $queryComponents The components of the query to execute |
||
| 835 | * @return \mysqli_stmt|object MySQLi statement / DBAL object |
||
| 836 | * @internal This method may only be called by \Fab\Vidi\Database\PreparedStatement |
||
| 837 | */ |
||
| 838 | public function prepare_PREPAREDquery($query, array $queryComponents) |
||
| 851 | |||
| 852 | /************************************** |
||
| 853 | * |
||
| 854 | * Various helper functions |
||
| 855 | * |
||
| 856 | * Functions recommended to be used for |
||
| 857 | * - escaping values, |
||
| 858 | * - cleaning lists of values, |
||
| 859 | * - stripping of excess ORDER BY/GROUP BY keywords |
||
| 860 | * |
||
| 861 | **************************************/ |
||
| 862 | /** |
||
| 863 | * Escaping and quoting values for SQL statements. |
||
| 864 | * |
||
| 865 | * @param string $str Input string |
||
| 866 | * @param string $table Table name for which to quote string. Just enter the table that the field-value is selected from (and any DBAL will look up which handler to use and then how to quote the string!). |
||
| 867 | * @param bool $allowNull Whether to allow NULL values |
||
| 868 | * @return string Output string; Wrapped in single quotes and quotes in the string (" / ') and \ will be backslashed (or otherwise based on DBAL handler) |
||
| 869 | * @see quoteStr() |
||
| 870 | */ |
||
| 871 | public function fullQuoteStr($str, $table, $allowNull = false) |
||
| 886 | |||
| 887 | /** |
||
| 888 | * Will fullquote all values in the one-dimensional array so they are ready to "implode" for an sql query. |
||
| 889 | * |
||
| 890 | * @param array $arr Array with values (either associative or non-associative array) |
||
| 891 | * @param string $table Table name for which to quote |
||
| 892 | * @param bool|array|string $noQuote List/array of keys NOT to quote (eg. SQL functions) - ONLY for associative arrays |
||
| 893 | * @param bool $allowNull Whether to allow NULL values |
||
| 894 | * @return array The input array with the values quoted |
||
| 895 | * @see cleanIntArray() |
||
| 896 | */ |
||
| 897 | public function fullQuoteArray($arr, $table, $noQuote = false, $allowNull = false) |
||
| 915 | |||
| 916 | /** |
||
| 917 | * Substitution for PHP function "addslashes()" |
||
| 918 | * Use this function instead of the PHP addslashes() function when you build queries - this will prepare your code for DBAL. |
||
| 919 | * NOTICE: You must wrap the output of this function in SINGLE QUOTES to be DBAL compatible. Unless you have to apply the single quotes yourself you should rather use ->fullQuoteStr()! |
||
| 920 | * |
||
| 921 | * @param string $str Input string |
||
| 922 | * @param string $table Table name for which to quote string. Just enter the table that the field-value is selected from (and any DBAL will look up which handler to use and then how to quote the string!). |
||
| 923 | * @return string Output string; Quotes (" / ') and \ will be backslashed (or otherwise based on DBAL handler) |
||
| 924 | * @see quoteStr() |
||
| 925 | */ |
||
| 926 | public function quoteStr($str, $table) |
||
| 934 | |||
| 935 | /** |
||
| 936 | * Escaping values for SQL LIKE statements. |
||
| 937 | * |
||
| 938 | * @param string $str Input string |
||
| 939 | * @param string $table Table name for which to escape string. Just enter the table that the field-value is selected from (and any DBAL will look up which handler to use and then how to quote the string!). |
||
| 940 | * @return string Output string; % and _ will be escaped with \ (or otherwise based on DBAL handler) |
||
| 941 | * @see quoteStr() |
||
| 942 | */ |
||
| 943 | public function escapeStrForLike($str, $table) |
||
| 948 | |||
| 949 | /** |
||
| 950 | * Will convert all values in the one-dimensional array to integers. |
||
| 951 | * Useful when you want to make sure an array contains only integers before imploding them in a select-list. |
||
| 952 | * |
||
| 953 | * @param array $arr Array with values |
||
| 954 | * @return array The input array with all values cast to (int) |
||
| 955 | * @see cleanIntList() |
||
| 956 | */ |
||
| 957 | public function cleanIntArray($arr) |
||
| 962 | |||
| 963 | /** |
||
| 964 | * Will force all entries in the input comma list to integers |
||
| 965 | * Useful when you want to make sure a commalist of supposed integers really contain only integers; You want to know that when you don't trust content that could go into an SQL statement. |
||
| 966 | * |
||
| 967 | * @param string $list List of comma-separated values which should be integers |
||
| 968 | * @return string The input list but with every value cast to (int) |
||
| 969 | * @see cleanIntArray() |
||
| 970 | */ |
||
| 971 | public function cleanIntList($list) |
||
| 976 | |||
| 977 | /** |
||
| 978 | * Removes the prefix "ORDER BY" from the input string. |
||
| 979 | * This function is used when you call the exec_SELECTquery() function and want to pass the ORDER BY parameter by can't guarantee that "ORDER BY" is not prefixed. |
||
| 980 | * Generally; This function provides a work-around to the situation where you cannot pass only the fields by which to order the result. |
||
| 981 | * |
||
| 982 | * @param string $str eg. "ORDER BY title, uid |
||
| 983 | * @return string eg. "title, uid |
||
| 984 | * @see exec_SELECTquery(), stripGroupBy() |
||
| 985 | */ |
||
| 986 | public function stripOrderBy($str) |
||
| 991 | |||
| 992 | /** |
||
| 993 | * Removes the prefix "GROUP BY" from the input string. |
||
| 994 | * This function is used when you call the SELECTquery() function and want to pass the GROUP BY parameter by can't guarantee that "GROUP BY" is not prefixed. |
||
| 995 | * Generally; This function provides a work-around to the situation where you cannot pass only the fields by which to order the result. |
||
| 996 | * |
||
| 997 | * @param string $str eg. "GROUP BY title, uid |
||
| 998 | * @return string eg. "title, uid |
||
| 999 | * @see exec_SELECTquery(), stripOrderBy() |
||
| 1000 | */ |
||
| 1001 | public function stripGroupBy($str) |
||
| 1006 | |||
| 1007 | /** |
||
| 1008 | * Returns the date and time formats compatible with the given database table. |
||
| 1009 | * |
||
| 1010 | * @param string $table Table name for which to return an empty date. Just enter the table that the field-value is selected from (and any DBAL will look up which handler to use and then how date and time should be formatted). |
||
| 1011 | * @return array |
||
| 1012 | */ |
||
| 1013 | public function getDateTimeFormats($table) |
||
| 1018 | |||
| 1019 | /** |
||
| 1020 | * Creates SELECT query components for selecting fields ($select) from two/three tables joined |
||
| 1021 | * Use $mm_table together with $local_table or $foreign_table to select over two tables. Or use all three tables to select the full MM-relation. |
||
| 1022 | * The JOIN is done with [$local_table].uid <--> [$mm_table].uid_local / [$mm_table].uid_foreign <--> [$foreign_table].uid |
||
| 1023 | * The function is very useful for selecting MM-relations between tables adhering to the MM-format used by TCE (TYPO3 Core Engine). See the section on $GLOBALS['TCA'] in Inside TYPO3 for more details. |
||
| 1024 | * |
||
| 1025 | * @param string $select See exec_SELECT_mm_query() |
||
| 1026 | * @param string $local_table See exec_SELECT_mm_query() |
||
| 1027 | * @param string $mm_table See exec_SELECT_mm_query() |
||
| 1028 | * @param string $foreign_table See exec_SELECT_mm_query() |
||
| 1029 | * @param string $whereClause See exec_SELECT_mm_query() |
||
| 1030 | * @param string $groupBy See exec_SELECT_mm_query() |
||
| 1031 | * @param string $orderBy See exec_SELECT_mm_query() |
||
| 1032 | * @param string $limit See exec_SELECT_mm_query() |
||
| 1033 | * @return array SQL query components |
||
| 1034 | */ |
||
| 1035 | protected function getSelectMmQueryParts($select, $local_table, $mm_table, $foreign_table, $whereClause = '', $groupBy = '', $orderBy = '', $limit = '') |
||
| 1054 | |||
| 1055 | /************************************** |
||
| 1056 | * |
||
| 1057 | * MySQL(i) wrapper functions |
||
| 1058 | * (For use in your applications) |
||
| 1059 | * |
||
| 1060 | **************************************/ |
||
| 1061 | /** |
||
| 1062 | * Executes query |
||
| 1063 | * MySQLi query() wrapper function |
||
| 1064 | * Beware: Use of this method should be avoided as it is experimentally supported by DBAL. You should consider |
||
| 1065 | * using exec_SELECTquery() and similar methods instead. |
||
| 1066 | * |
||
| 1067 | * @param string $query Query to execute |
||
| 1068 | * @return bool|\mysqli_result|object MySQLi result object / DBAL object |
||
| 1069 | */ |
||
| 1070 | View Code Duplication | public function sql_query($query) |
|
| 1079 | |||
| 1080 | /** |
||
| 1081 | * Returns the error status on the last query() execution |
||
| 1082 | * |
||
| 1083 | * @return string MySQLi error string. |
||
| 1084 | */ |
||
| 1085 | public function sql_error() |
||
| 1090 | |||
| 1091 | /** |
||
| 1092 | * Returns the error number on the last query() execution |
||
| 1093 | * |
||
| 1094 | * @return int MySQLi error number |
||
| 1095 | */ |
||
| 1096 | public function sql_errno() |
||
| 1101 | |||
| 1102 | /** |
||
| 1103 | * Returns the number of selected rows. |
||
| 1104 | * |
||
| 1105 | * @param bool|\mysqli_result|object $res MySQLi result object / DBAL object |
||
| 1106 | * @return int Number of resulting rows |
||
| 1107 | */ |
||
| 1108 | public function sql_num_rows($res) |
||
| 1117 | |||
| 1118 | /** |
||
| 1119 | * Returns an associative array that corresponds to the fetched row, or FALSE if there are no more rows. |
||
| 1120 | * MySQLi fetch_assoc() wrapper function |
||
| 1121 | * |
||
| 1122 | * @param bool|\mysqli_result|object $res MySQLi result object / DBAL object |
||
| 1123 | * @return array|bool Associative array of result row. |
||
| 1124 | */ |
||
| 1125 | View Code Duplication | public function sql_fetch_assoc($res) |
|
| 1139 | |||
| 1140 | /** |
||
| 1141 | * Returns an array that corresponds to the fetched row, or FALSE if there are no more rows. |
||
| 1142 | * The array contains the values in numerical indices. |
||
| 1143 | * MySQLi fetch_row() wrapper function |
||
| 1144 | * |
||
| 1145 | * @param bool|\mysqli_result|object $res MySQLi result object / DBAL object |
||
| 1146 | * @return array|bool Array with result rows. |
||
| 1147 | */ |
||
| 1148 | View Code Duplication | public function sql_fetch_row($res) |
|
| 1162 | |||
| 1163 | /** |
||
| 1164 | * Free result memory |
||
| 1165 | * free_result() wrapper function |
||
| 1166 | * |
||
| 1167 | * @param bool|\mysqli_result|object $res MySQLi result object / DBAL object |
||
| 1168 | * @return bool Returns TRUE on success or FALSE on failure. |
||
| 1169 | */ |
||
| 1170 | public function sql_free_result($res) |
||
| 1180 | |||
| 1181 | /** |
||
| 1182 | * Get the ID generated from the previous INSERT operation |
||
| 1183 | * |
||
| 1184 | * @return int The uid of the last inserted record. |
||
| 1185 | */ |
||
| 1186 | public function sql_insert_id() |
||
| 1191 | |||
| 1192 | /** |
||
| 1193 | * Returns the number of rows affected by the last INSERT, UPDATE or DELETE query |
||
| 1194 | * |
||
| 1195 | * @return int Number of rows affected by last query |
||
| 1196 | */ |
||
| 1197 | public function sql_affected_rows() |
||
| 1201 | |||
| 1202 | /** |
||
| 1203 | * Move internal result pointer |
||
| 1204 | * |
||
| 1205 | * @param bool|\mysqli_result|object $res MySQLi result object / DBAL object |
||
| 1206 | * @param int $seek Seek result number. |
||
| 1207 | * @return bool Returns TRUE on success or FALSE on failure. |
||
| 1208 | */ |
||
| 1209 | public function sql_data_seek($res, $seek) |
||
| 1218 | |||
| 1219 | /** |
||
| 1220 | * Get the type of the specified field in a result |
||
| 1221 | * mysql_field_type() wrapper function |
||
| 1222 | * |
||
| 1223 | * @param bool|\mysqli_result|object $res MySQLi result object / DBAL object |
||
| 1224 | * @param int $pointer Field index. |
||
| 1225 | * @return string Returns the name of the specified field index, or FALSE on error |
||
| 1226 | */ |
||
| 1227 | public function sql_field_type($res, $pointer) |
||
| 1261 | |||
| 1262 | /** |
||
| 1263 | * Open a (persistent) connection to a MySQL server |
||
| 1264 | * |
||
| 1265 | * @return bool|void |
||
| 1266 | * @throws \RuntimeException |
||
| 1267 | */ |
||
| 1268 | public function sql_pconnect() |
||
| 1335 | |||
| 1336 | /** |
||
| 1337 | * Select a SQL database |
||
| 1338 | * |
||
| 1339 | * @return bool Returns TRUE on success or FALSE on failure. |
||
| 1340 | */ |
||
| 1341 | public function sql_select_db() |
||
| 1357 | |||
| 1358 | /************************************** |
||
| 1359 | * |
||
| 1360 | * SQL admin functions |
||
| 1361 | * (For use in the Install Tool and Extension Manager) |
||
| 1362 | * |
||
| 1363 | **************************************/ |
||
| 1364 | /** |
||
| 1365 | * Listing databases from current MySQL connection. NOTICE: It WILL try to select those databases and thus break selection of current database. |
||
| 1366 | * This is only used as a service function in the (1-2-3 process) of the Install Tool. |
||
| 1367 | * In any case a lookup should be done in the _DEFAULT handler DBMS then. |
||
| 1368 | * Use in Install Tool only! |
||
| 1369 | * |
||
| 1370 | * @return array Each entry represents a database name |
||
| 1371 | * @throws \RuntimeException |
||
| 1372 | */ |
||
| 1373 | public function admin_get_dbs() |
||
| 1399 | |||
| 1400 | /** |
||
| 1401 | * Returns the list of tables from the default database, TYPO3_db (quering the DBMS) |
||
| 1402 | * In a DBAL this method should 1) look up all tables from the DBMS of |
||
| 1403 | * the _DEFAULT handler and then 2) add all tables *configured* to be managed by other handlers |
||
| 1404 | * |
||
| 1405 | * @return array Array with tablenames as key and arrays with status information as value |
||
| 1406 | */ |
||
| 1407 | View Code Duplication | public function admin_get_tables() |
|
| 1420 | |||
| 1421 | /** |
||
| 1422 | * Returns information about each field in the $table (quering the DBMS) |
||
| 1423 | * In a DBAL this should look up the right handler for the table and return compatible information |
||
| 1424 | * This function is important not only for the Install Tool but probably for |
||
| 1425 | * DBALs as well since they might need to look up table specific information |
||
| 1426 | * in order to construct correct queries. In such cases this information should |
||
| 1427 | * probably be cached for quick delivery. |
||
| 1428 | * |
||
| 1429 | * @param string $tableName Table name |
||
| 1430 | * @return array Field information in an associative array with fieldname => field row |
||
| 1431 | */ |
||
| 1432 | View Code Duplication | public function admin_get_fields($tableName) |
|
| 1445 | |||
| 1446 | /** |
||
| 1447 | * Returns information about each index key in the $table (quering the DBMS) |
||
| 1448 | * In a DBAL this should look up the right handler for the table and return compatible information |
||
| 1449 | * |
||
| 1450 | * @param string $tableName Table name |
||
| 1451 | * @return array Key information in a numeric array |
||
| 1452 | */ |
||
| 1453 | View Code Duplication | public function admin_get_keys($tableName) |
|
| 1466 | |||
| 1467 | /** |
||
| 1468 | * Returns information about the character sets supported by the current DBM |
||
| 1469 | * This function is important not only for the Install Tool but probably for |
||
| 1470 | * DBALs as well since they might need to look up table specific information |
||
| 1471 | * in order to construct correct queries. In such cases this information should |
||
| 1472 | * probably be cached for quick delivery. |
||
| 1473 | * |
||
| 1474 | * This is used by the Install Tool to convert tables with non-UTF8 charsets |
||
| 1475 | * Use in Install Tool only! |
||
| 1476 | * |
||
| 1477 | * @return array Array with Charset as key and an array of "Charset", "Description", "Default collation", "Maxlen" as values |
||
| 1478 | */ |
||
| 1479 | View Code Duplication | public function admin_get_charsets() |
|
| 1492 | |||
| 1493 | /** |
||
| 1494 | * mysqli() wrapper function, used by the Install Tool and EM for all queries regarding management of the database! |
||
| 1495 | * |
||
| 1496 | * @param string $query Query to execute |
||
| 1497 | * @return bool|\mysqli_result|object MySQLi result object / DBAL object |
||
| 1498 | */ |
||
| 1499 | View Code Duplication | public function admin_query($query) |
|
| 1508 | |||
| 1509 | /****************************** |
||
| 1510 | * |
||
| 1511 | * Connect handling |
||
| 1512 | * |
||
| 1513 | ******************************/ |
||
| 1514 | |||
| 1515 | /** |
||
| 1516 | * Set database host |
||
| 1517 | * |
||
| 1518 | * @param string $host |
||
| 1519 | */ |
||
| 1520 | public function setDatabaseHost($host = 'localhost') |
||
| 1525 | |||
| 1526 | /** |
||
| 1527 | * Set database port |
||
| 1528 | * |
||
| 1529 | * @param int $port |
||
| 1530 | */ |
||
| 1531 | public function setDatabasePort($port = 3306) |
||
| 1536 | |||
| 1537 | /** |
||
| 1538 | * Set database socket |
||
| 1539 | * |
||
| 1540 | * @param string|NULL $socket |
||
| 1541 | */ |
||
| 1542 | public function setDatabaseSocket($socket = null) |
||
| 1547 | |||
| 1548 | /** |
||
| 1549 | * Set database name |
||
| 1550 | * |
||
| 1551 | * @param string $name |
||
| 1552 | */ |
||
| 1553 | public function setDatabaseName($name) |
||
| 1558 | |||
| 1559 | /** |
||
| 1560 | * Set database username |
||
| 1561 | * |
||
| 1562 | * @param string $username |
||
| 1563 | */ |
||
| 1564 | public function setDatabaseUsername($username) |
||
| 1569 | |||
| 1570 | /** |
||
| 1571 | * Set database password |
||
| 1572 | * |
||
| 1573 | * @param string $password |
||
| 1574 | */ |
||
| 1575 | public function setDatabasePassword($password) |
||
| 1580 | |||
| 1581 | /** |
||
| 1582 | * Set persistent database connection |
||
| 1583 | * |
||
| 1584 | * @param bool $persistentDatabaseConnection |
||
| 1585 | * @see http://php.net/manual/de/mysqli.persistconns.php |
||
| 1586 | */ |
||
| 1587 | public function setPersistentDatabaseConnection($persistentDatabaseConnection) |
||
| 1592 | |||
| 1593 | /** |
||
| 1594 | * Set connection compression. Might be an advantage, if SQL server is not on localhost |
||
| 1595 | * |
||
| 1596 | * @param bool $connectionCompression TRUE if connection should be compressed |
||
| 1597 | */ |
||
| 1598 | public function setConnectionCompression($connectionCompression) |
||
| 1603 | |||
| 1604 | /** |
||
| 1605 | * Set commands to be fired after connection was established |
||
| 1606 | * |
||
| 1607 | * @param array $commands List of SQL commands to be executed after connect |
||
| 1608 | */ |
||
| 1609 | public function setInitializeCommandsAfterConnect(array $commands) |
||
| 1614 | |||
| 1615 | /** |
||
| 1616 | * Set the charset that should be used for the MySQL connection. |
||
| 1617 | * The given value will be passed on to mysqli_set_charset(). |
||
| 1618 | * |
||
| 1619 | * The default value of this setting is utf8. |
||
| 1620 | * |
||
| 1621 | * @param string $connectionCharset The connection charset that will be passed on to mysqli_set_charset() when connecting the database. Default is utf8. |
||
| 1622 | */ |
||
| 1623 | public function setConnectionCharset($connectionCharset = 'utf8') |
||
| 1628 | |||
| 1629 | /** |
||
| 1630 | * Connects to database for TYPO3 sites: |
||
| 1631 | * |
||
| 1632 | * @throws \RuntimeException |
||
| 1633 | * @throws \UnexpectedValueException |
||
| 1634 | */ |
||
| 1635 | public function connectDB() |
||
| 1688 | |||
| 1689 | /** |
||
| 1690 | * Checks if database is connected |
||
| 1691 | * |
||
| 1692 | * @return bool |
||
| 1693 | */ |
||
| 1694 | public function isConnected() |
||
| 1704 | |||
| 1705 | /** |
||
| 1706 | * Checks if the current connection character set has the same value |
||
| 1707 | * as the connectionCharset variable. |
||
| 1708 | * |
||
| 1709 | * To determine the character set these MySQL session variables are |
||
| 1710 | * checked: character_set_client, character_set_results and |
||
| 1711 | * character_set_connection. |
||
| 1712 | * |
||
| 1713 | * If the character set does not match or if the session variables |
||
| 1714 | * can not be read a RuntimeException is thrown. |
||
| 1715 | * |
||
| 1716 | * @throws \RuntimeException |
||
| 1717 | */ |
||
| 1718 | protected function checkConnectionCharset() |
||
| 1780 | |||
| 1781 | /** |
||
| 1782 | * Disconnect from database if connected |
||
| 1783 | */ |
||
| 1784 | protected function disconnectIfConnected() |
||
| 1791 | |||
| 1792 | /** |
||
| 1793 | * Returns current database handle |
||
| 1794 | * |
||
| 1795 | * @return \mysqli|NULL |
||
| 1796 | */ |
||
| 1797 | public function getDatabaseHandle() |
||
| 1802 | |||
| 1803 | /** |
||
| 1804 | * Set current database handle, usually \mysqli |
||
| 1805 | * |
||
| 1806 | * @param \mysqli $handle |
||
| 1807 | */ |
||
| 1808 | public function setDatabaseHandle($handle) |
||
| 1812 | |||
| 1813 | /** |
||
| 1814 | * Get the MySQL server version |
||
| 1815 | * |
||
| 1816 | * @return string |
||
| 1817 | */ |
||
| 1818 | public function getServerVersion() |
||
| 1823 | |||
| 1824 | /****************************** |
||
| 1825 | * |
||
| 1826 | * Debugging |
||
| 1827 | * |
||
| 1828 | ******************************/ |
||
| 1829 | /** |
||
| 1830 | * Debug function: Outputs error if any |
||
| 1831 | * |
||
| 1832 | * @param string $func Function calling debug() |
||
| 1833 | * @param string $query Last query if not last built query |
||
| 1834 | */ |
||
| 1835 | public function debug($func, $query = '') |
||
| 1854 | |||
| 1855 | /** |
||
| 1856 | * Checks if record set is valid and writes debugging information into devLog if not. |
||
| 1857 | * |
||
| 1858 | * @param bool|\mysqli_result|object MySQLi result object / DBAL object |
||
| 1859 | * @return bool TRUE if the record set is valid, FALSE otherwise |
||
| 1860 | */ |
||
| 1861 | public function debug_check_recordset($res) |
||
| 1890 | |||
| 1891 | /** |
||
| 1892 | * Explain select queries |
||
| 1893 | * If $this->explainOutput is set, SELECT queries will be explained here. Only queries with more than one possible result row will be displayed. |
||
| 1894 | * The output is either printed as raw HTML output or embedded into the TS admin panel (checkbox must be enabled!) |
||
| 1895 | * |
||
| 1896 | * @todo Feature is not DBAL-compliant |
||
| 1897 | * |
||
| 1898 | * @param string $query SQL query |
||
| 1899 | * @param string $from_table Table(s) from which to select. This is what comes right after "FROM ...". Required value. |
||
| 1900 | * @param int $row_count Number of resulting rows |
||
| 1901 | * @return bool TRUE if explain was run, FALSE otherwise |
||
| 1902 | */ |
||
| 1903 | protected function explain($query, $from_table, $row_count) |
||
| 1982 | |||
| 1983 | /** |
||
| 1984 | * Serialize destructs current connection |
||
| 1985 | * |
||
| 1986 | * @return array All protected properties that should be saved |
||
| 1987 | */ |
||
| 1988 | public function __sleep() |
||
| 2006 | |||
| 2007 | /** |
||
| 2008 | * function to call a deprecation log entry (but only once per request / class) |
||
| 2009 | */ |
||
| 2010 | protected function logDeprecation() |
||
| 2019 | } |
||
| 2020 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.