$charset = 'utf8mb4';
}
+ if ( 'utf8mb4' === $charset && ! $this->has_cap( 'utf8mb4' ) ) {
+ $charset = 'utf8';
+ $collate = str_replace( 'utf8mb4_', 'utf8_', $collate );
+ }
+
if ( 'utf8mb4' === $charset ) {
// _general_ is outdated, so we can upgrade it to _unicode_, instead.
if ( ! $collate || 'utf8_general_ci' === $collate ) {
*
* @uses wpdb::_real_escape()
* @since 2.8.0
- * @access private
+ * @access public
*
* @param string|array $data
* @return string|array escaped
*/
- function _escape( $data ) {
+ public function _escape( $data ) {
if ( is_array( $data ) ) {
foreach ( $data as $k => $v ) {
- if ( is_array($v) )
+ if ( is_array( $v ) ) {
$data[$k] = $this->_escape( $v );
- else
+ } else {
$data[$k] = $this->_real_escape( $v );
+ }
}
} else {
$data = $this->_real_escape( $data );
*
* Both %d and %s should be left unquoted in the query string.
*
- * wpdb::prepare( "SELECT * FROM `table` WHERE `column` = %s AND `field` = %d", 'foo', 1337 )
- * wpdb::prepare( "SELECT DATE_FORMAT(`field`, '%%c') FROM `table` WHERE `column` = %s", 'foo' );
+ * $wpdb->prepare( "SELECT * FROM `table` WHERE `column` = %s AND `field` = %d", 'foo', 1337 );
+ * $wpdb->prepare( "SELECT DATE_FORMAT(`field`, '%%c') FROM `table` WHERE `column` = %s", 'foo' );
*
* @link https://secure.php.net/sprintf Description of syntax.
* @since 2.3.0
wp_load_translations_early();
- if ( $caller = $this->get_caller() )
+ if ( $caller = $this->get_caller() ) {
+ /* translators: 1: Database error message, 2: SQL query, 3: Name of the calling function */
$error_str = sprintf( __( 'WordPress database error %1$s for query %2$s made by %3$s' ), $str, $this->last_query, $caller );
- else
+ } else {
+ /* translators: 1: Database error message, 2: SQL query */
$error_str = sprintf( __( 'WordPress database error %1$s for query %2$s' ), $str, $this->last_query );
+ }
error_log( $error_str );
* @since 0.71
*
* @param string|null $query SQL query.
- * @param string $output Optional. one of ARRAY_A | ARRAY_N | OBJECT constants.
- * Return an associative array (column => value, ...),
- * a numerically indexed array (0 => value, ...) or
- * an object ( ->column = value ), respectively.
+ * @param string $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which correspond to
+ * an stdClass object, an associative array, or a numeric array, respectively. Default OBJECT.
* @param int $y Optional. Row to return. Indexed from 0.
* @return array|object|null|void Database query result in format specified by $output or null on failure
*/
. '|INSERT(?:\s+LOW_PRIORITY|\s+DELAYED|\s+HIGH_PRIORITY)?(?:\s+IGNORE)?(?:\s+INTO)?'
. '|REPLACE(?:\s+LOW_PRIORITY|\s+DELAYED)?(?:\s+INTO)?'
. '|UPDATE(?:\s+LOW_PRIORITY)?(?:\s+IGNORE)?'
- . '|DELETE(?:\s+LOW_PRIORITY|\s+QUICK|\s+IGNORE)*(?:\s+FROM)?'
+ . '|DELETE(?:\s+LOW_PRIORITY|\s+QUICK|\s+IGNORE)*(?:.+?FROM)?'
. ')\s+((?:[0-9a-zA-Z$_.`-]|[\xC2-\xDF][\x80-\xBF])+)/is', $query, $maybe ) ) {
return str_replace( '`', '', $maybe[1] );
}
- // SHOW TABLE STATUS and SHOW TABLES
- if ( preg_match( '/^\s*(?:'
- . 'SHOW\s+TABLE\s+STATUS.+(?:LIKE\s+|WHERE\s+Name\s*=\s*)'
- . '|SHOW\s+(?:FULL\s+)?TABLES.+(?:LIKE\s+|WHERE\s+Name\s*=\s*)'
- . ')\W((?:[0-9a-zA-Z$_.`-]|[\xC2-\xDF][\x80-\xBF])+)\W/is', $query, $maybe ) ) {
- return str_replace( '`', '', $maybe[1] );
+ // SHOW TABLE STATUS and SHOW TABLES WHERE Name = 'wp_posts'
+ if ( preg_match( '/^\s*SHOW\s+(?:TABLE\s+STATUS|(?:FULL\s+)?TABLES).+WHERE\s+Name\s*=\s*("|\')((?:[0-9a-zA-Z$_.-]|[\xC2-\xDF][\x80-\xBF])+)\\1/is', $query, $maybe ) ) {
+ return $maybe[2];
+ }
+
+ // SHOW TABLE STATUS LIKE and SHOW TABLES LIKE 'wp\_123\_%'
+ // This quoted LIKE operand seldom holds a full table name.
+ // It is usually a pattern for matching a prefix so we just
+ // strip the trailing % and unescape the _ to get 'wp_123_'
+ // which drop-ins can use for routing these SQL statements.
+ if ( preg_match( '/^\s*SHOW\s+(?:TABLE\s+STATUS|(?:FULL\s+)?TABLES)\s+(?:WHERE\s+Name\s+)?LIKE\s*("|\')((?:[\\\\0-9a-zA-Z$_.-]|[\xC2-\xDF][\x80-\xBF])+)%?\\1/is', $query, $maybe ) ) {
+ return str_replace( '\\_', '_', $maybe[2] );
}
// Big pattern for the rest of the table-related queries.
public function check_database_version() {
global $wp_version, $required_mysql_version;
// Make sure the server has the required MySQL version
- if ( version_compare($this->db_version(), $required_mysql_version, '<') )
+ if ( version_compare($this->db_version(), $required_mysql_version, '<') ) {
+ /* translators: 1: WordPress version number, 2: Minimum required MySQL version number */
return new WP_Error('database_version', sprintf( __( '<strong>ERROR</strong>: WordPress %1$s requires MySQL %2$s or higher' ), $wp_version, $required_mysql_version ));
+ }
}
/**