phputf-8mysqlicharacter-encodingcollation

Why do i have to use set_charset("utf8") even though everything is utf-8 encoded? (MySQLi-PHP)


My table's collation is utf8_general_ci.

My pages are encoded with UTF-8 (without BOM).

Within my pages, my Equiv meta tag sets character set to utf8

My data has Turkish characters in it.

When i output them, it's not showing them as it should be but when i do $db->set_charset("utf8");, it works.

Why do i have to use $db->set_charset("utf8"); even though everything is utf-8 encoded?


Solution

  • The data is stored as UTF-8 in MySQL, but the PHP's client connection collation is not. Which is why you have to use set_charset in PHP for the DB connection.

    Update

    php.ini : default_charset utf-8
    .htaccess : AddDefaultCharset utf-8