Friday, October 21, 2011

PDO utf-8 issues

Had issues with json_encode complaining:
Invalid UTF-8 sequence in argument 

Fixed it by adding

PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"
to the PDO creation line.. ie:
$pdo = new PDO(
    'mysql:host=mysql.example.com;dbname=example_db',
    "username",
    "password",
    array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));


source

No comments:

Post a Comment