Last Updated: February 25, 2016
·
4.009K
· cristianmedeiros

PDO and MySQL with UTF-8

If you're using PDO, and facing dificulties with UTF-8 in your MySQL, even with everything setup to use UTF-8, you could try this:

$pdo = new PDO(    
        "mysql:host    =localhost;dbname=databasename",     
        "user",    
        "pass",     
        array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8")
);