According to php.net, StackOverflow and other sources of trust, I can find 4 different ways to install UTF-8 in a PDO connection, but I can not find which one is better to choose.
PDO connection code (and some inits):
$localhost = $_SERVER['SERVER_NAME'] == 'localhost'; error_reporting(-1); ini_set('display_errors', $localhost); // Old : error_reporting($localhost ? -1 : 0); see answer above date_default_timezone_set('Europe/Paris'); $pdo_db = 'mysql:host=localhost;dbname=local_db;charset=utf8'; // METHOD
So, I realized that method 1 only works with PHP 5.3+ (but it seems to be a little buggy), and method 2 only for MySQL. The differences between MySQL methods 3 and 4 are a 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 just for MySQL?
Thanks!
php pdo database-connection
Joan
source share