db_version(); $message = sprintf( __( 'Your Webserver is running MySQL version %1$s, but its latest stable branch is %2$s. WordPress highly recommends MySQL 5 or higher, because MySQL 4 is full of gotchas. Please contact your host and have them upgrade MySQL accordingly.', 'health-check' ), $version, HEALTH_CHECK_MYSQL_VERSION, 'http://sql-info.de/mysql/gotchas.html' ); $passed = $this->assertTrue( version_compare('5.0.0', $version, '<'), $message, HEALTH_CHECK_RECOMMENDATION ); if ( $passed || HEALTH_CHECK_DEBUG ) { // no point in raising this twice $message = sprintf( __( 'Your Webserver is running MySQL version %1$s, but its latest stable branch is %2$s. Please contact your host and have them upgrade MySQL.', 'health-check' ), $version, HEALTH_CHECK_MYSQL_VERSION ); // invert the check because version_compare('1.0', '1.0.0', '>=') returns false $this->assertTrue( version_compare($version, HEALTH_CHECK_MYSQL_VERSION, '>='), $message, HEALTH_CHECK_INFO ); } } } HealthCheck::register_test('HealthCheck_MySQL_Version'); /** * Check that we can use mysql_real_escape_string() * * @link http://core.trac.wordpress.org/ticket/11819 * @link http://php.net/manual/en/function.mysql-set-charset.php * @link http://php.net/manual/en/function.mysql-real-escape-string.php */ class HealthCheck_MySQL_Escape extends HealthCheckTest { function run_test() { $message = sprintf( __( 'Your Webserver does not support the mysql_set_charset() function, which we\'ve found is needed in order to safely use the mysql_real_escape_string() function. This can have security implications on your site, depending on the plugins you use. Please contact your host and have them upgrade your server accordingly.', 'health-check' ), 'http://php.net/manual/en/function.mysql-set-charset.php', 'http://core.trac.wordpress.org/ticket/11819', 'http://php.net/manual/en/function.mysql-real-escape-string.php' ); $this->assertTrue( function_exists('mysql_set_charset'), $message, HEALTH_CHECK_RECOMMENDATION ); } } HealthCheck::register_test('HealthCheck_MySQL_Escape'); /** * Check that the MySQL database has the same charset as WordPress * * Ideally, the database should entirely run in UTF-8. Whether it does can be * tested by running the following MySQL statement: * * SHOW VARIABLES LIKE 'char%'; * * The my.cnf file needs to contain the following for all of it to use utf8: * * [client] * default-character-set=utf8 * * [mysqld] * character-set-server=utf8 * * We've no means to check how this is set using mysql_client_encoding(), however. * The client library bundled with PHP does not read the my.cnf option file: * * http://bugs.mysql.com/bug.php?id=11362 * * Nonetheless, we can check the database's charset. It should be using the same as * the one defined in the wp-config.php file, in the event a plugin creates a table. * * MySQL enforces xxx_general_ci as a collation when the charset changes. If a site * is using a non-english language, it may make sense to suggest using a different * collation among the available ones on the server. * * @link http://dev.mysql.com/doc/refman/5.0/en/charset-collation-effect.html * @link http://dev.mysql.com/doc/refman/5.0/en/charset-configuration.html * @link http://dev.mysql.com/doc/refman/5.0/en/charset-unicode-sets.html * @link http://bugs.mysql.com/bug.php?id=11362 */ class HealthCheck_MySQL_Charset extends HealthCheckTest { function run_test() { // Skip test if we've no DB_CHARSET if ( ( !defined('DB_CHARSET') || !DB_CHARSET ) && !HEALTH_CHECK_DEBUG ) return; global $wpdb; $db_charset = $wpdb->get_var('SHOW CREATE DATABASE `' . DB_NAME . '`', 1); preg_match("/CHARACTER SET ([a-z0-9_]+)/i", $db_charset, $db_charset); $db_charset = end($db_charset); $table_charset = $wpdb->get_var('SHOW CREATE TABLE `' . $wpdb->posts . '`', 1); preg_match("/CHARSET\s*=\s*([a-z0-9_]+)/i", $table_charset, $table_charset); $table_charset = end($table_charset); $blog_charset = strtoupper(get_option('blog_charset', 'UTF-8')); $passed = true; // We need a conversion table to properly test the first one $blog2mysql = array( 'UTF-8' => 'utf8', ); if ( isset($blog2mysql[$blog_charset]) || HEALTH_CHECK_DEBUG ) { $message = sprintf( __( 'Your WordPress installation is using the %1$s character set, whereas your WordPress database is configured to use the %2$s character set. Using inconsistent character sets and collations can lead to quirky behaviors. You can change this setting in your wp-config.php file. A line should read: define("DB_CHARSET", "%4$s");' ), $blog_charset, DB_CHARSET, 'http://dev.mysql.com/doc/refman/5.0/en/charset-collation-effect.html', $blog2mysql[$blog_charset] ); $passed &= $this->assertEquals($blog2mysql[$blog_charset], strtolower(DB_CHARSET), $message, HEALTH_CHECK_INFO ); } $message = sprintf( __( 'Your WordPress database tables are using the %1$s character set, whereas your WordPress database is configured to use the %2$s character set. Using inconsistent character sets and collations can lead to quirky behaviors. The instructions to fix this can be a bit challenging for non-technically oriented users, however, so merely keep this in mind as notice notice.', 'health-check' ), $table_charset, DB_CHARSET, 'http://dev.mysql.com/doc/refman/5.0/en/charset-collation-effect.html', 'http://codex.wordpress.org/Converting_Database_Character_Sets'); $passed &= $this->assertEquals( strtolower($table_charset), strtolower(DB_CHARSET), $message, HEALTH_CHECK_INFO ); if ( $passed && WPLANG && !preg_match("/^en\b/i", WPLANG) || HEALTH_CHECK_DEBUG ) { // in this check, we'll assume that if it's set to any value, it is the correct one. $message = sprintf( __( 'Your WordPress installation is localized as %1$s, but your database is using the %3$s_general_ci collation. This can result in oddly ordered results when retrieving data from your database. Please check with your host to know if a collation that is more appropriate for your language might be available on your server. To change a table\'s collation, run (or have your host run) the following SQL in PhpMyAdmin: ALTER TABLE `tablename` CONVERT TO CHARACTER SET %4$s COLLATE %3$s_newcollation_ci.', 'health-check' ), WPLANG, 'http://dev.mysql.com/doc/refman/5.0/en/charset-unicode-sets.html', $blog2mysql[$blog_charset], DB_CHARSET); $this->assertNotEquals( DB_COLLATE, '', $message, HEALTH_CHECK_INFO ); } $message = sprintf( __( 'Your WordPress database is using the %1$s character set by default, whereas you\'ve configured WordPress to use the %2$s character set. WordPress handles this quite fine, but not all plugins do when they create or alter database tables, and using inconsistent character sets and collations can lead to quirky behaviors. To change this, run (or have your host run) the following SQL in PhpMyAdmin: ALTER DATABASE `%4$s` DEFAULT CHARACTER SET %2$s.', 'health-check' ), $db_charset, DB_CHARSET, 'http://dev.mysql.com/doc/refman/5.0/en/charset-collation-effect.html', DB_NAME); $this->assertEquals(strtolower($db_charset), strtolower(DB_CHARSET), $message, HEALTH_CHECK_RECOMMENDATION ); } } HealthCheck::register_test('HealthCheck_MySQL_Charset'); ?>