From 86fd171713e28eb8915271783a26bcfbd797c8a0 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Tue, 2 Aug 2022 16:33:00 +0000 Subject: [PATCH] Database: Suppress errors when checking the validity of table prefix during installation. There are some table prefixes (for example, `7e1_`), which the database will try and parse as values unless they are quoted in backticks. Because not everyone remembers to quote their table names, WordPress discourages use of such prefixes during setup. To test if the table prefix is valid, WordPress executes a query deliberately trying to generate an error: > `Unknown column 'wp_' in 'field list'` which means the prefix is safe to use, as the database was not able to parse it as a value. Previously, this error would not be displayed to the user in a typical configuration, but would be logged on the server via `wpdb::print_error()`, and in some cases could block the installation. This commit makes sure the error is still checked to display a proper message in case the prefix needs to be edited, but otherwise is silently discarded instead of being logged. Follow-up to [37581], [41631], [51582]. Props pento, lazam786, Velochicdunord, irecinius, mikemanzo, dd32, blackawxs, codewhy, psykro, burgiuk, mdrago, maythamalsudany, peterwilsoncc, sumitsingh, deksar, SergeyBiryukov. Fixes #42362. git-svn-id: https://develop.svn.wordpress.org/trunk@53812 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/setup-config.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/wp-admin/setup-config.php b/src/wp-admin/setup-config.php index b1b7a16ccb..bf5e1c84c3 100644 --- a/src/wp-admin/setup-config.php +++ b/src/wp-admin/setup-config.php @@ -311,9 +311,10 @@ switch ( $step ) { wp_die( $wpdb->error->get_error_message() . $tryagain_link ); } - $errors = $wpdb->hide_errors(); + $errors = $wpdb->suppress_errors(); $wpdb->query( "SELECT $prefix" ); - $wpdb->show_errors( $errors ); + $wpdb->suppress_errors( $errors ); + if ( ! $wpdb->last_error ) { // MySQL was able to parse the prefix as a value, which we don't want. Bail. wp_die( __( 'Error: "Table Prefix" is invalid.' ) );