While you should edit my.conf to change the default character set to 'utf8' and collation to 'utf8_general_ci' if possible for future databases, the following script should convert your existing database.
1. Create convert.php in your vBulletin root folder, with contents:
Code:
<?php
//error_reporting(-1);
define('THIS_SCRIPT', 'conversion');
$globaltemplates = array();
$phrasegroups = array();
$specialtemplates = array();
$actiontemplates = array();
require_once('./global.php');
$db->query_write("
ALTER DATABASE `" . $vbulletin->config['Database']['dbname'] . "`
DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci
");
$tables = $db->query_read("SHOW TABLE STATUS");
while ($table = $db->fetch_array($tables))
{
if ($table['Collation'] != 'utf8_general_ci')
{
echo $table['Name'] . "\n";
echo "Collation: $table[Collation]\n";
$db->query_write("
ALTER TABLE $table[Name]
DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci
");
$cols = $db->query_read("SHOW FULL COLUMNS FROM $table[Name]");
$update_cols = array();
while ($col = $db->fetch_array($cols))
{
if ($coll['Collation'] === NULL)
{
continue;
}
if ($col['Collation'] != 'utf8_general_ci')
{
echo "-- $col[Name]\n";
echo "-- Collation: $col[Collation]\n";
$def = "$col[type] CHARACTER SET utf8 COLLATE utf8_general_ci";
if ($col['Null'])
{
$def .= " NULL";
if ($col['Default'] === NULL)
{
$def .= " DEFAULT NULL";
}
}
else if ($col['Default'] !== NULL)
{
$def .= " DEFAULT '" . $db->escape_string($col['Default']) . "'";
}
if ($col['Extra'])
{
$def .= " $col[Extra]";
}
$update_cols[] = "CHANGE $col[Name] $col[Name] $def";
}
}
$db->free_result($cols);
if ($update_cols)
{
$db->query_write("
ALTER TABLE $table[Name]
" . implode(",\n", $update_cols) . "
");
}
}
}
$db->free_result($tables);
2. Visit convert.php.
3. Confirm that some tables on your database are updated.
4. Delete convert.php.
Bookmarks