-1

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.

João M. S. Silva
  • 1,078
  • 2
  • 11
  • 24
  • The character can change at any point, is it sent correctly to DB, does db write it correctly, on reading it is the read correct? Take a look at http://stackoverflow.com/questions/279170/utf-8-all-the-way-through. – chris85 Mar 11 '16 at 20:20
  • @chris85 You should add that as the answer. It can change anywhere. – Harry Mar 11 '16 at 20:38
  • @chris85, I see the character correctly displayed with PDO queries in HTML. It is also correctly displayed in `mysql> select * from ;`, so I assume it is well written in the table, as UTF-8. The problem seems to reside either with the MySQL++ query or the C/C++ output command.
    – João M. S. Silva Mar 11 '16 at 22:25

1 Answers1

0

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();
João M. S. Silva
  • 1,078
  • 2
  • 11
  • 24