Skip to content

Instantly share code, notes, and snippets.

@jpustula
Created August 27, 2010 15:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpustula/553628 to your computer and use it in GitHub Desktop.
Save jpustula/553628 to your computer and use it in GitHub Desktop.
Convert phpBB3's database and tables to Unicode
<?php
/**
* Convert phpBB3's database and tables to Unicode
*
* @author Jarosław Pustuła <kontakt@weeb.pl>
* @license http://www.gnu.org/licenses/gpl.html
*/
/*$dbms = '';
$dbhost = '';
$dbport = '';
$dbname = '';
$dbuser = '';
$dbpasswd = '';*/
include 'config.php';
switch ($dbms)
{
case 'mysql':
case 'mysqli':
case 'postgres':
$dsn = ($dbms === 'postgres') ? 'pgsql:' : 'mysql:';
if (!empty($dbhost))
{
$dsn .= "host=$dbhost;";
}
if (!empty($dbport))
{
$dsn .= "port=$dbport;";
}
if (!empty($dbname))
{
$dsn .= "dbname=$dbname;";
}
break;
}
$pdo = new PDO($dsn, $dbuser, $dbpasswd);
// Set encoding for database
$sql = 'DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci';
$pdo->exec($sql);
// Get list of tables
$sql = 'SHOW TABLES';
$result = $pdo->query($sql);
// Convert each table encoding
foreach ($result as $table)
{
$sql = "ALTER TABLE $table[0] CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin";
$pdo->exec($sql);
echo $table[0] . '&#133; Done<br />';
}
$result->closeCursor();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment