My web server on Windows 7 displays all utf-8 chars well but not on Linux even both MySQL database is created with "CHARACTER SET utf8 COLLATE utf8_unicode_ci", and all php pages are created with utf-8. Where is the problem pn Linux: Apache configuration or php5 configuration? Both use Apache as web server.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
For some reason, it doesn't work out. In the code, PDO is used as below:
new PDO("mysql:host={$dbhost};dbname={$db};charset=utf8",$userid, $pw,
array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
Also, I check mysql, all setting is utf8 as below. Use Aqua Data Studio to display, it doesn't show correct, even correct by connecting to mysql on Windows. More strange is another page using mysqli displaying the content correct. Do this mean the problem is PDO?
Before the string is sent to mysql, it's handled by addslashes function.
Have you tried doing the SET NAMES 'utf8' COLLATE 'utf8_unicode_ci' query before doing any other queries (read or write)?
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
It's proved the problem is PHP MySQL PDO module: in the same php page, both mysqli and PDO are used in almost the same way, the same query by mysqli displays result properly, but not the one with PDO:
mysqli: displays - This is a 鮓lunch menu
PDO: displays -This is a 鮓lunch menu
In Windows platform (both PHP and MySQL installed on Windows), both are the same.
Even PDO constructs the connection with utf8 as below:
$pdo = new PDO("mysql:host={$dbhost};dbname={$db};charset=utf8",$userid, $pw,
array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
Please help where is problem the above pdo statement. I'm told PDO has more advantage.
Bookmarks