Repost: UTF-8, PHP and MySQL

Posted on: Mar 23, 2009 by wenbert

This is a repost from Akrabat.com

The Problem:Get a £ (that is the pound sign) character stored to MySQL, retrieved and then displayed without any weird characters in front of it using UTF8.

//for the browser//header("Content-type: text/html; charset=utf-8");//OR////then for MySQLmysql_set_charset('utf8');//ormysqli_set_charset('utf8');//or execute the SQL immediately after connection://SET NAMES UTF8;//for PDO$handle = new PDO("mysql:host=localhost;dbname=dbname",    'username', 'password',    array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));//and finally for Zend_Db$params = array(    'host' => 'localhost',    'username' => 'username',    'password' => 'password',    'dbname' => 'dbname',    'driver_options' => array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES UTF8;'););$db = Zend_Db::factory('PDO_MYSQL', $params);

A million thanks to Rob for this post.


Subscribe to comments Comment | Trackback |
Post Tags: , ,

Browse Timeline


Add a Comment


XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">


© Copyright 2007 eKini Web Developer Blog . Thanks for visiting!