According to php.net, Stack Overflow and other sources of trust, I can find 4 different ways to set UTF-8 on PDO connection, but can't find which one is the better to choose:
$pdo_db = 'mysql:host=localhost;dbname=local_db;charset=utf8'; // METHOD #1
$pdo_login = 'root';
$pdo_pass = 'localpass';
$db = new PDO($pdo_db, $pdo_login, $pdo_pass, array(
PDO::ATTR_ERRMODE => $localhost ? PDO::ERRMODE_EXCEPTION : PDO::ERRMODE_SILENT,
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8', // METHOD #2
));
$db->exec('SET NAMES utf8'); // METHOD #3
$db->exec('SET CHARACTER SET utf8'); // METHOD #4
So, what I understood, is that method 1 only works with PHP 5.3+ (but it seems that it's a bit buggy), and method 2 is for MySQL only. Differences between method 3 and 4 is MySQL thing, but I still don't know which one is better. And is there a way to call SET NAMES in PDO attributes, but not for MySQL only?