Created
March 21, 2011 10:51
-
-
Save mattattui/879290 to your computer and use it in GitHub Desktop.
Opening a UTF-8 connection to MySQL with PHP PDO
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
try { | |
$dbh = new PDO('MySQL:host=localhost;dbname=example', | |
$username, $password, | |
array(PDO::MySQL_ATTR_INIT_COMMAND => 'SET NAMES utf8')); | |
} catch (PDOException $e) { | |
// You probably want to handle DB failure better than this: | |
die('Oh no, the database is dead!'); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See http://inanimatt.com/php-charsets.php for explanation