3 responses to “UTF-8 in MySQL — Solving UTF-8 Issues in MySQL”

  1. Suresh V

    I am having some problem. Please help.The problem is that I use Google SpreadSheets PHP API(using the help of your article “Saving Form Data to Google Spreadsheets Using PHP and the Google Docs API: “) to get data from the sheets. Everything works fine. Except that my PHP script displays spanish characters incorrectly.

    print “$row”;

    so something like ñer gets displayed as ñer.

    when I try and put the data in MySql. Same problem. I have changed my php.ini file, mysql settings. Everything really. I can give details of the settings. But nothing seems to work for me.

  2. Suresh V

    Hi Dimas,

    I tried quite a lot of things. Everything is working except this spanish character issue. The below is the first instance where I get the row data from Zend GData API.

    $row=$Col->getText(); //getText is the Google API that returns the value in the row.
    print “$row”; // I print the content

    When I print it, it does not display the special characters properly.

    I tried various different things such as edit the PHP file and add:

    mbstring.language = Neutral ; Set default language to Neutral(UTF-8) (default)
    mbstring.internal_encoding = UTF-8 ; Set default internal encoding to UTF-8
    mbstring.encoding_translation = On ; HTTP input encoding translation is enabled
    mbstring.http_input = auto ; Set HTTP input character set dectection to auto
    mbstring.http_output = UTF-8 ; Set HTTP output encoding to UTF-8
    mbstring.detect_order = auto ; Set default character encoding detection order to auto
    mbstring.substitute_character = none ; Do not print invalid characters
    default_charset = UTF-8 ; Default character set for auto content type header
    mbstring.func_overload = 7 ; All non-multibyte-safe functions are overloaded with the mbstring alternatives

    Add in the below in MySql

    init_connect=’SET collation_connection = utf8_unicode_ci; SET NAMES utf8;’

    Change Database and Table properties

    ALTER DATABASE db_name
    COLLATE utf8_general_ci
    DEFAULT COLLATE utf8_general_ci

    ALTER TABLE tbl_name
    COLLATE utf8_general_ci

    Call SETNAMES etc just after mysql open connection.

    $q=”SET NAMES ‘utf8′”;
    mysql_query(“SET CHARACTER SET utf8”);

    But nothing seems to work. I guess I have another frustrating day ahead of me.