Script - How To Convert Table to UTF8_bin
1. Copy and paste this script. Save to ConvertToUTF8.php.
2. Change database info to appropriate, dbuser to database user, dbpass to database password and dbname to database name.
<? php
// Database info
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "";
$dbname = "smachdb";
//—————
header("Content-type: text/plain");
$dbconn = mysql_connect($dbhost, $dbuser, $dbpass) or die( mysql_error() );
$db = mysql_select_db($dbname) or die( mysql_error() );
$sql = "SHOW TABLES";
$result = mysql_query($sql) or die( mysql_error() );
while ( $row = mysql_fetch_row($result) )
{
$table = mysql_real_escape_string($row[0]);
$sql = "ALTER TABLE $table DEFAULT CHARACTER SET utf8 COLLATE utf8_bin";
mysql_query($sql) or die( mysql_error() );
print "$table changed to UTF-8.\n";
}
mysql_close($dbconn);
?>
2. Change database info to appropriate, dbuser to database user, dbpass to database password and dbname to database name.
<? php
// Database info
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "";
$dbname = "smachdb";
//—————
header("Content-type: text/plain");
$dbconn = mysql_connect($dbhost, $dbuser, $dbpass) or die( mysql_error() );
$db = mysql_select_db($dbname) or die( mysql_error() );
$sql = "SHOW TABLES";
$result = mysql_query($sql) or die( mysql_error() );
while ( $row = mysql_fetch_row($result) )
{
$table = mysql_real_escape_string($row[0]);
$sql = "ALTER TABLE $table DEFAULT CHARACTER SET utf8 COLLATE utf8_bin";
mysql_query($sql) or die( mysql_error() );
print "$table changed to UTF-8.\n";
}
mysql_close($dbconn);
?>
Comments