MySql spanish character data

前端 未结 3 1163
一整个雨季
一整个雨季 2021-01-14 05:19

i hav a database that contains spanish characters. to populate the database i am getting the values from client page which has character encoding=UTF-8. when i insert the va

相关标签:
3条回答
  • 2021-01-14 06:05

    Change your mysql database/ table / column encoding to UTF-8 (and also set the collation to a compatible value).

    ALTER TABLE mytable CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
    ALTER TABLE mytable 
    MODIFY country CHAR(50) 
    CHARACTER SET utf8 COLLATE utf8_general_ci;
    

    Also specify the char set at the PHP side when connecting.

    mysql_set_charset('utf8',$conn); 
    

    Take a look at this article for further info and a script to batch change every table / column in a database.

    0 讨论(0)
  • 2021-01-14 06:09

    Check two things first:

    • Are you inserting the data as UTF-8? If the data is coming from a web page, make sure the page's encoding is set to UTF-8 (encoding meta tag is set in the page header).
    • Are you sure the data is not saved as Unicode? This is the reverse situation: if phpMyAdmin uses something else other than UTF-8, you'd see the garbled characters when it displays the contents.
    0 讨论(0)
  • 2021-01-14 06:16

    I just wasted 4 hours on the same problem as you.

    Everything is in UTF-8

    EG:

    <meta charset="UTF-8">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    

    The MySQL database is in UTF-8 PHP is in UTF-8

    After four hours and on many occasions tearing my hair out I have found a solution that works.

    $content = htmlentities($row[mystring], ENT_QUOTES, "ISO-8859-1");
    $content = html_entity_decode($content);
    

    It takes the accents converts them to html characters then converts them back into UTF-8

    This is a great hack and it works perfectly.

    For some inexplicable reason, the data in my MYSQL database is not in the UTF-8 format even though I have gone to extreme measures like exporting the data to a text file in phpmyadmin saving it as UTF-8 in a text editor and re-importing it. None of this worked.

    0 讨论(0)
提交回复
热议问题