phpmysqlpdomysql++

Where does character encoding change?


I have a MySQL database with a table with entries with accents, like "João".

The entries are selected with a MySQL++ query in C/C++ code, but this entry in particular is printed as "Jo�o" (printf, fprintf or std::cout <<).

What I'd like to understand is: where in the data flow is this character being encoded incorrectly?

Some more context: the front-end is HTML/PHP, which uses PDO to insert the data into the MySQL database.

I see the character correctly displayed with PDO queries in HTML. It is also correctly displayed with:

mysql> select * from <table>;

so I assume it is well written in the table. The problem seems to reside either with the MySQL++ query or the C/C++ output command.

I don't know if it is relevant, but MySQL's table encoding is utf8_general_ci and shell locale is LANG=en_US.UTF-8.


Solution

  • I got the answer from this post: http://forums.mysql.com/read.php?167,243667,243695#msg-243695

    The problem is with MySQL++. After creating the connection, we need to execute:

    mysqlpp::Query query = connection->query("SET NAMES 'utf8'");
    query.execute();