I had this previously in my normal mysql_* connection:
JavaScript
x
mysql_set_charset("utf8",$link);
mysql_query("SET NAMES 'UTF8'");
Do I need it for the PDO? And where should I have it?
JavaScript
$connect = new PDO("mysql:host=$host;dbname=$db", $user, $pass, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
Advertisement
Answer
You’ll have it in your connection string like:
JavaScript
"mysql:host=$host;dbname=$db;charset=utf8mb4"
HOWEVER, prior to PHP 5.3.6, the charset option was ignored. If you’re running an older version of PHP, you must do it like this:
JavaScript
$dbh = new PDO("mysql:host=$host;dbname=$db", $user, $password);
$dbh->exec("set names utf8mb4");