-1

My Database has as

  • Default collation: utf8_unicode_ci
  • Default characterset: utf8

All of my Databases have:

  • Collation: utf8_unicode_ci

My Mainpage is saved as utf8, has utf8-meta-charset and a php utf8-header. So is my Ajax-loaded Page. However, characters like ä, ö, ü are displayed: "?"

If I set the names at the beginning of my mainpage

set names utf8 COLLATE 'utf8_general_ci'

The Ajax-loaded Content is correct but my mainpage ö,ü... are displayed "?" The Mainpage content is via mb_detect_encoding($str); still utf8...

Where should I look?

Note: Every Content is included via include_once So index.php->loged.php->content.php

orgertot
  • 197
  • 16
  • are the files saved/encoded as UTF-8 too? check that. This page may help too http://stackoverflow.com/questions/279170/utf-8-all-the-way-through – Funk Forty Niner Aug 05 '15 at 14:16
  • Yes.. I went through every file again and saved it as utf-8.. – orgertot Aug 05 '15 at 14:23
  • Are you setting all the same things for both the "main" page and the AJAX request? What does the data in the database itself look like? Check with some admin utility like phpMyAdmin. – deceze Aug 05 '15 at 14:51

2 Answers2

0

To get your site working with UTF-8:

  1. Set the charset to the php connection object (not to be confused with the database settings) $mysqliDb->set_charset('utf8');
  2. Encode the PHP page with UTF-8, this has to be done by your code editor.

I tried to point out all important points in this short article.

EDIT:

For PDO the syntax to set the charset would be:

$dsn = "mysql:host=$dbHost;dbname=$dbName;charset=utf8";
$db = new PDO($dsn, $dbUser, $dbPassword);
martinstoeckli
  • 23,430
  • 6
  • 56
  • 87
  • Yeah.. I did that.. But as I mentioned is the characterset in the Mainpage content not right... :/ – orgertot Aug 05 '15 at 14:27
  • @orgertot - So you set the charset in your PHP code, or is it a setting in your database? What class do you use to access mysql (mysqli or PDO)? – martinstoeckli Aug 05 '15 at 14:29
  • Both.. I mean.. If i use `mb_detect_encoding($str)` it says utf8.. But i dont know why it is not displayed correctly.. – orgertot Aug 05 '15 at 14:31
  • @orgertot - This does not answer the question, did you set the charset in your PHP code, or do you only trust the mb_detect_encoding() function? Can you show us the code which sets the charset? – martinstoeckli Aug 05 '15 at 14:33
  • I dont know what you mean.. Im using: `$dbh->exec("set names utf8 COLLATE 'utf8_general_ci'");` for pdo and `header("Content-type:text/html; charset=utf-8");` and `` – orgertot Aug 05 '15 at 14:37
  • @orgertot - I added an example to the answer. Setting the collation is not the same as setting the charset, the collation is only used for comparisons (sorting). – martinstoeckli Aug 05 '15 at 14:44
  • I added this to my project. The Mainpage content is still `ää` Thanks for your help so far! – orgertot Aug 05 '15 at 14:47
  • @orgertot - Then try to store a new value to the databaes and show this value. Make sure you set the charset **before** you store the value and before you make the query. – martinstoeckli Aug 05 '15 at 14:49
0

you can try to do mysqldump, review the contents of the dump to make sure content is utf-8 encoded. If not, convert it to utf-8 and import dump back.

if that will fix your problem, then a script which save data into your database saves it in the wrong encoding.

alex b
  • 24
  • 3