1 2 3
$this->pdo = new PDO("mysql:host=".$this->host."; dbname=".$this->databaseName,
array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
Monday, May 24, 2010
I had some issues displaying localized text in a PHP based internal tool recently, it turns out the solution was really simple-the MySql connection just needs to know that the connection must be UTF8. Probably no-brainer stuff for all you PHP-Ninjas.. news to me :) To do this with a PDO connection, just add an init command when you create the PDO command:
Thanks to Rob Allen for the tip, variation for other connection methods can be found on his blog.