3

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!

denlau
  • 916
  • 2
  • 9
  • 21

1 Answers1

1

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.

Manolis Agkopian
  • 1,033
  • 13
  • 22
  • My database is set to UTF-8 and collation to UTF-8-general. My encoding on the files is UTF-8 and my HTML encoding is also UTF-8 – denlau Sep 22 '12 at 00:25
  • In that case after every $con = mysql_connect() add these lines: mysql_query("SET NAMES 'utf8'", $con); mysql_set_charset('UTF-8', $con); Edit: After selecting a database – Manolis Agkopian Sep 22 '12 at 00:27
  • Also if still don't work try to set the headers to UTF-8 ini_set('default_charset', 'utf-8') – Manolis Agkopian Sep 22 '12 at 00:37
  • Still not working :) The part about the mysql_query doesn't work - i use PDO.. Don't really know how I should implement it :) – denlau Sep 22 '12 at 01:33
  • Sorry I don't use PDO but you can check out this topic http://stackoverflow.com/questions/4361459/php-pdo-charset-set-names. I had the same problem before with a website after I uploaded from my localhost to a remote host and these lines solved the problem. – Manolis Agkopian Sep 22 '12 at 11:59
  • Thanks - it actually gave the answer.. I just needed to add charset to my connection :) – denlau Sep 22 '12 at 12:25