How do i change my entire database (including fields!) to UTF-8?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chromis
    New Member
    • Jan 2008
    • 113

    How do i change my entire database (including fields!) to UTF-8?

    Hi,

    I've been struggling to find a solution this problem, I have found the following php script:

    Code:
    <?php
    $db = mysql_connect('localhost','myuser_mydbuser','mypassword');
    if(!$db) echo "Cannot connect to the database - incorrect details";
    mysql_select_db('myuser_mydbname'); $result=mysql_query('show tables');
    while($tables = mysql_fetch_array($result)) {
    foreach ($tables as $key => $value) {
    mysql_query("ALTER TABLE $value COLLATE utf8_general_ci");
    }}
    echo "The collation of your database has been successfully changed!";
    ?>
    This however does not do what it says on the tin, instead it just changes the table collation to utf8_general_ci , what I need is for it to change the fields as well as these are remaining the same.

    Is there a fast way to do this?

    The reason why i 'think' i need to do this is so that i can server up pages AND RSS feeds encoded in the utf-8 format, as I am having trouble with wierd characters in my feed.

    Thanks,

    Chromis
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi.

    I am not sure that changing the charset of your database will have the effect you are hoping for.

    If you need to display ISO characters in a Unicode page, try using the utf8_encode function.

    Comment

    Working...