Character problem with PHP and phpMyAdmin

I’ve had this problem for ages and can’t quite figure it out. It’s no big deal but thought I’d ask all the same…

I have everything set on my MySQL database to utf8 (utf8_general_ci). All my PHP files have UTF8 encoding (meta tag and text file). My PHP scripts send and receive data from MySQL no problem.

However, in phpMyAdmin, even though the connection is set to UTF8 any special characters (E.g. “”*&^%$£@!) sent from my PHP scripts, don’t show up correctly in phpMyAdmin.

I know it’s a bit of a vague question but am I missing something? I tried it with some MySQL desktop clients as well (Navicat and Sequel Pro) and I get the same results so it’s not a problem with phpMyAdmin itself.

I wonder if it is to do with my hoster’s settings. When I go to Variables in phpMyAdmin I get this:

character set client utf8
(Global value) latin1
character set connection utf8
(Global value) latin1
character set database latin1
character set filesystem binary
character set results utf8
(Global value) latin1
character set server latin1
character set system utf8
character sets dir /usr/share/mysql/charsets/
collation connection utf8_general_ci
(Global value) latin1_swedish_ci
collation database latin1_swedish_ci
collation server latin1_swedish_ci

I’m bumping this as I never got to the bottom of it. Any ideas?

Assuming you’re using the MySQLi extension use mysqli_set_charset() to specify that you want the connection to use UTF8. You need to use that right after yo have established the connection to the database

Thanks for the reply. It does not seem to make any difference though. It’s so strange; everything is encoded to UTF-8 and everything within my own CMS is fine. It’s just some characters appear as illegal when using Sequel Pro or phpMyAdmin. Is there anything else I can try?

I found this code on another thread:

mysqli_query($link, “SET NAMES utf8”);

And it seems to solve the issue. Anyone know why? Everything is already set to UTF-8, the char set of the script sending the data and the receiving database so I don’t get what this does—or why it is needed.

Thanks. :slight_smile: