WordPress 2.3.3 および WordPress mu 1.3.3 を MySQL 3 で使う

別に MySQL のバージョン上げればいいだけの話なんですけどね。
今時 MySQL 3 とかね、そもそも 4 ですらかったるいのに。
新規にインストールする際にもコードの修正が必要なはずですが、忘れました。アップグレードする方法。

wp-admin/includes/upgrade.php

アップグレードスクリプトMySQL バージョンチェック関数を無効にします。
1255行目から。
↓元のコード

function wp_check_mysql_version() {
	global $wp_version;

	// Make sure the server has MySQL 4.0
	$mysql_version = preg_replace('|[^0-9\.]|', '', @mysql_get_server_info());
	if ( version_compare($mysql_version, '4.0.0', '<') )
		die(sprintf(__('<strong>ERROR</strong>: WordPress %s requires MySQL 4.0.0 or higher'), $wp_version));
}

を下のように書き換える。コメントアウトするだけです。

function wp_check_mysql_version() {
	global $wp_version;

	// Make sure the server has MySQL 4.0
	$mysql_version = preg_replace('|[^0-9\.]|', '', @mysql_get_server_info());
	//if ( version_compare($mysql_version, '4.0.0', '<') )
	//	die(sprintf(__('<strong>ERROR</strong>: WordPress %s requires MySQL 4.0.0 or higher'), $wp_version));
}

wp-content/plugins/mysql3.php

クエリを修正するプラグインを作り、動作させます。

<?php
/*
Plugin Name: WordPress 2.3.3 for MySQL 3
Plugin URI: 
Description: 
Author: chrono-meter
Version: 0.01
Author URI: http://d.hatena.ne.jp/chrono-meter/
*/


// MySQL 3 compatibility
$mysql3_lastquery = '';
function mysql3_query($query){

	global $mysql3_lastquery;

	if (strstr($query, 'FOUND_ROWS()'))
	{
		$query = $mysql3_lastquery;
		$query = 'SELECT COUNT(*) ' . strstr($query, 'FROM');
		$query = substr($query, 0, strrpos($query, 'LIMIT'));
	}
	else if (strstr($query, 'SQL_CALC_FOUND_ROWS'))
	{
		$query = str_replace('SQL_CALC_FOUND_ROWS', '', $query);
	}

	$mysql3_lastquery = $query;

	return $query;
}
add_filter('query', 'mysql3_query');


?>