Make WordPress Core

Changeset 53812


Ignore:
Timestamp:
08/02/2022 04:33:00 PM (2 years ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/setup-config.php

    r53745 r53812  
    312312        }
    313313
    314         $errors = $wpdb->hide_errors();
     314        $errors = $wpdb->suppress_errors();
    315315        $wpdb->query( "SELECT $prefix" );
    316         $wpdb->show_errors( $errors );
     316        $wpdb->suppress_errors( $errors );
     317
    317318        if ( ! $wpdb->last_error ) {
    318319            // MySQL was able to parse the prefix as a value, which we don't want. Bail.
Note: See TracChangeset for help on using the changeset viewer.