If you need to use UTF8 charset and want to convert your database charset to UTF8 here is a simple way to do it:
- Make sure you backup your database (If your database is new no need to think about that)
- Now open your notepad and Copy & Paste code below:
[php]<?php
// Database info$dbhost = "localhost";
$dbuser = "db_user";
$dbpass = "your_dbpass";
$dbname = "your_dbname";//—————
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_general_ci, CONVERT TO CHARACTER SET utf8";
mysql_query($sql) or die( mysql_error() );
print "$table changed to UTF-8.\n";
}mysql_close($dbconn);
?>[/php] - Edit database username & password data in the code.
- Save that file as convert2Utf8.php and upload to your site’s base/admin directory.
- Browse that file using your browser (Eg. http://myserver.com/convert2Utf8.php)
- Check for the results..
This simple php script converts all the tables to UTF8.
Cheers!


One Comment
thanks this helped a lot
One Trackback