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.
Built from https://develop.svn.wordpress.org/trunk@53812


git-svn-id: http://core.svn.wordpress.org/trunk@53371 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2022-08-02 16:34:13 +00:00
parent 46c1425601
commit d7d371b840
2 changed files with 4 additions and 3 deletions

View File

@ -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( __( '<strong>Error:</strong> "Table Prefix" is invalid.' ) );

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.1-alpha-53811';
$wp_version = '6.1-alpha-53812';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.