Skip to content

Instantly share code, notes, and snippets.

@mattattui
Created March 21, 2011 10:51
Show Gist options
  • Save mattattui/879290 to your computer and use it in GitHub Desktop.
Save mattattui/879290 to your computer and use it in GitHub Desktop.
Opening a UTF-8 connection to MySQL with PHP PDO
<?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!');
}
?>
@mattattui
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment