h1

Character encoding with PHP and MySQL

September 21, 2010

Today had a problem reading UTF-8 encoded characters from MySQL using PHP. After connecting to the MySQL database I needed to explictly set the character encoding standard, PHP MySQL driver did not seem to automatically know what the db was set to. I am using the PDO method with PHP and MySQL…

$PDO = new PDO('mysql:host=myhost;dbname=db', $username, $password);
$PDO->exec('SET CHARSET SET utf8');
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: