-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.

4

1 回答 1

0

我从这篇文章中得到了答案: http: //forums.mysql.com/read.php?167,243667,243695#msg-243695

问题出在 MySQL++ 上。创建连接后,我们需要执行:

mysqlpp::Query query = connection->query("SET NAMES 'utf8'");
query.execute();
于 2016-03-12T20:46:52.697 回答