Coppermine Photo Gallery で、phpMyAdmin から日本語のテーブルデータを覗くと文字化け。その対応の備忘録です。
こちらの環境は、
・MySQL 4.1.19
・Apache 1.3.37
・PHP 4.4.2
・phpMyAdmin 2.10.0
・Coppermine Photo Gallery 1.4.10
こちらの情報を元に、
Coppermine Photo Gallery は日本語に UTF-8 を使うので、
(1)新規テーブル作成時に照合順序に utf8_unicode_ci を選択する
(2)include/function.ini.php の 184行目あたりを、
--- 修正前
function cpg_db_connect()
{
global $CONFIG;
$result = @mysql_connect($CONFIG['dbserver'], $CONFIG['dbuser'], $CONFIG['dbpass']);
if (!$result) {
return false;
}
if (!mysql_select_db($CONFIG['dbname']))
return false;
return $result;
}
--- 修正後
function cpg_db_connect()
{
global $CONFIG;
$result = @mysql_connect($CONFIG['dbserver'], $CONFIG['dbuser'], $CONFIG['dbpass']);
if (!$result) {
return false;
} else { // ← ここ追加
mysql_query("SET NAMES utf8", $result); // ← ここ追加
} // ← ここ追加
if (!mysql_select_db($CONFIG['dbname']))
return false;
return $result;
}
することで文字化けがなくなりました。