游.程 2015-08-05 14:15 采纳率: 0%
浏览 39

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

  • 写回答

2条回答 默认 最新

  • 衫裤跑路 2015-08-05 14:25
    关注

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

报告相同问题?