Created
August 27, 2010 15:56
-
-
Save jpustula/553628 to your computer and use it in GitHub Desktop.
Convert phpBB3's database and tables to Unicode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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] . '… Done<br />'; | |
} | |
$result->closeCursor(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment