Make WordPress Core

Changeset 55367


Ignore:
Timestamp:
02/20/2023 04:03:17 PM (20 months ago)
Author:
SergeyBiryukov
Message:

Bootstrap/Load: Check that either mysqli_connect() or mysql_connect() is available.

This resolves a fatal error and displays an actionable message if the mysqli PHP extension is missing.

Previously, wp_check_php_mysql_versions() performed an early check whether mysql, mysqli, or mysqlnd extensions are loaded, but that did not work if the mysqlnd extension is the only one present.

Checking specifically for mysqli_connect() or mysql_connect() functions should be a more reliable approach and more closely mirrors the existing checks in the wpdb class.

Follow-up to [1955], [4489], [7234], [12732], [19760], [27257], [36434].

Props bgin, desrosj, dimadin, ipajen, hellofromTonya, sc0ttkclark, azaozz, SergeyBiryukov.
Fixes #51988.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/load.php

    r55148 r55367  
    150150        header( sprintf( '%s 500 Internal Server Error', $protocol ), true, 500 );
    151151        header( 'Content-Type: text/html; charset=utf-8' );
    152         printf( 'Your server is running PHP version %1$s but WordPress %2$s requires at least %3$s.', $php_version, $wp_version, $required_php_version );
     152        printf(
     153            'Your server is running PHP version %1$s but WordPress %2$s requires at least %3$s.',
     154            $php_version,
     155            $wp_version,
     156            $required_php_version
     157        );
    153158        exit( 1 );
    154159    }
    155160
    156     if ( ! extension_loaded( 'mysql' ) && ! extension_loaded( 'mysqli' ) && ! extension_loaded( 'mysqlnd' )
     161    if ( ! function_exists( 'mysqli_connect' ) && ! function_exists( 'mysql_connect' )
    157162        // This runs before default constants are defined, so we can't assume WP_CONTENT_DIR is set yet.
    158163        && ( defined( 'WP_CONTENT_DIR' ) && ! file_exists( WP_CONTENT_DIR . '/db.php' )
     
    161166        require_once ABSPATH . WPINC . '/functions.php';
    162167        wp_load_translations_early();
     168
     169        $message = '<p>' . __( 'Your PHP installation appears to be missing the MySQL extension which is required by WordPress.' ) . "</p>\n";
     170
     171        $message .= '<p>' . sprintf(
     172            /* translators: %s: mysqli. */
     173            __( 'Please check that the %s PHP extension is installed and enabled.' ),
     174            '<code>mysqli</code>'
     175        ) . "</p>\n";
     176
     177        $message .= '<p>' . sprintf(
     178            /* translators: %s: Support forums URL. */
     179            __( 'If you are unsure what these terms mean you should probably contact your host. If you still need help you can always visit the <a href="%s">WordPress Support Forums</a>.' ),
     180            __( 'https://wordpress.org/support/forums/' )
     181        ) . "</p>\n";
     182
    163183        $args = array(
    164184            'exit' => false,
     
    166186        );
    167187        wp_die(
    168             __( 'Your PHP installation appears to be missing the MySQL extension which is required by WordPress.' ),
     188            $message,
    169189            __( 'Requirements Not Met' ),
    170190            $args
Note: See TracChangeset for help on using the changeset viewer.