denlau
denlau

Reputation: 1016

Encoding on database content not working

I'm currently having some charset problems, that I can't solve myself. My problem is, that when I use some special characters, I just get a "�"

It is ONLY on database content - so content written directly in my view files is shown correctly, but when it is coming from a database, it gives the above problem.

Does anyone know what I maybe should look for? At the moment I haven't got any more ideas myself.

SOLLUTION

Changing my connection line to PDO from:

self::$_db = new PDO(self::$DB_type .':host='. self::$DB_hostname .';dbname='. self::$DB_database, self::$DB_username, self::$DB_pass );

And simply add the charset - so the connection line is as following:

$options = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8');
self::$_db = new PDO(self::$DB_type .':host='. self::$DB_hostname .';dbname='. self::$DB_database, self::$DB_username, self::$DB_pass, $options );

Thanks in advance!

Upvotes: 3

Views: 299

Answers (1)

Manolis Agkopian
Manolis Agkopian

Reputation: 1094

Try to set your database encoding to UTF-8, do the same with your html code and save your php files as UTF-8.

In your html, inside head tags add this line:

     <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">

Your database should be utf8_general_ci, and for the php files download an editor like notepad++ and and from menu encoding choose UTF_8 without BOOM.

Upvotes: 1

Related Questions