Here’s a little experimental script to correct encoding mishaps in MYSQL dumps. Use with care, YMMV.
(via @threehz)
<?php
//script to fix busted utf-8 encoding
$username = 'YOURUSERNAME';
$password = 'YOURPASSWORD';
$mysql = mysql_connect( 'localhost', $username, $password );
if(!$mysql)
{
echo 'Cannot connect to database.';
exit;
}
// put in your database name here:
$db = 'apr_drupal_2';
$tablequery = "SHOW TABLES FROM ".$db;
$tablequery_result = mysql_query($tablequery);
while($tablerow = mysql_fetch_array($tablequery_result))
{
$table = $tablerow[0];
$fieldsquery = "select * from ".$db.".".$table."";
$fields_result = mysql_query($fieldsquery);
$num_fields = mysql_num_fields($fields_result);
for (
$j = 0; $j < $num_fields ; $j++)
{
$column = mysql_field_name($fields_result, $j);
$query = "select ".$column." from ".$db.".".$table."";
$result = mysql_query($query);
$num_result = mysql_num_rows($result);
for (
$i = 0; $i < $num_result; $i++)
{
$thing1 = mysql_result($result,$i);
//echo $thing1.'<br>';
$thing2 = utf8_decode($thing1);
//echo $thing2;
$queryreplace = "update ".$db.".".$table." set ".$column." = '".$thing2."' where ".$column." = '".$thing1."'";
//echo $queryreplace."<br>";
mysql_query($queryreplace);
}
}
}
?>


Comments
looks like the script itself needs to be fixed here ;)
Just a little error with my code filter. It should be sorted now.
Add your comment