Q:

PHP PDO: chars ÖÄÅ wont show

Whatever im trying to do. If i insert into with öäå or making a while loop, from rows that are from the db, and contains öäå, it appears like Ã¶Ã¤Ã¥.
It must has something to do with the PDO, because it worked just fine with the mysql_*.
Although I had these attributes in mysql_* :
# mysql_set_charset("utf8",$link);
# mysql_query("SET NAMES 'UTF8'");

My connection in PDO looks like this:
$connect = new PDO("mysql:host=".DB_HOST.";dbname=".DB_NAME.";charset:UTF-8", DB_USER, DB_PASS, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));

How can I solve this? I believe I also need the "set names" somewhere, how?

A:

The SET NAMES 'UTF8' statement is correct, but you have to execute it every time. You can instruct PDO to automatically run the command:
$dsn = sprintf( 'mysql:dbname=%s;host=%s', DB_NAME, DB_HOST );
$driver_options = array( PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8' );
try {
    $dbc = new pdo($dsn, $user, $pw, $driver_options);
}
catch (PDOException $e) {
    // Handle exception
}

(via Galen Grover)

