PHP Mysql:字符集

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

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);

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.