久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<small id='BFWlN'></small><noframes id='BFWlN'>

  1. <i id='BFWlN'><tr id='BFWlN'><dt id='BFWlN'><q id='BFWlN'><span id='BFWlN'><b id='BFWlN'><form id='BFWlN'><ins id='BFWlN'></ins><ul id='BFWlN'></ul><sub id='BFWlN'></sub></form><legend id='BFWlN'></legend><bdo id='BFWlN'><pre id='BFWlN'><center id='BFWlN'></center></pre></bdo></b><th id='BFWlN'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='BFWlN'><tfoot id='BFWlN'></tfoot><dl id='BFWlN'><fieldset id='BFWlN'></fieldset></dl></div>
    • <bdo id='BFWlN'></bdo><ul id='BFWlN'></ul>

      <legend id='BFWlN'><style id='BFWlN'><dir id='BFWlN'><q id='BFWlN'></q></dir></style></legend>
    1. <tfoot id='BFWlN'></tfoot>

    2. 如何讓 MySQL 返回 UTF-8?

      How do I make MySQL return UTF-8?(如何讓 MySQL 返回 UTF-8?)

      <i id='IxpZe'><tr id='IxpZe'><dt id='IxpZe'><q id='IxpZe'><span id='IxpZe'><b id='IxpZe'><form id='IxpZe'><ins id='IxpZe'></ins><ul id='IxpZe'></ul><sub id='IxpZe'></sub></form><legend id='IxpZe'></legend><bdo id='IxpZe'><pre id='IxpZe'><center id='IxpZe'></center></pre></bdo></b><th id='IxpZe'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='IxpZe'><tfoot id='IxpZe'></tfoot><dl id='IxpZe'><fieldset id='IxpZe'></fieldset></dl></div>

      <small id='IxpZe'></small><noframes id='IxpZe'>

      1. <tfoot id='IxpZe'></tfoot>
        <legend id='IxpZe'><style id='IxpZe'><dir id='IxpZe'><q id='IxpZe'></q></dir></style></legend>
          <tbody id='IxpZe'></tbody>
            • <bdo id='IxpZe'></bdo><ul id='IxpZe'></ul>

              1. 本文介紹了如何讓 MySQL 返回 UTF-8?的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                問題描述

                我正在使用 PHPUnit 來驗(yàn)證來自我的 PHP 代碼的 XML 輸出,但顯然我在字符編碼方面遇到了問題 MySQL 返回.這是我從 DOMDocument 得到的錯(cuò)誤:

                I'm using PHPUnit to validate XML output from my PHP code, but apparently I have problems with the character encoding MySQL returns. Here is the error I get from DOMDocument:

                Input is not proper UTF-8, indicate encoding!
                Bytes: 0xE9 0x20 0x42 0x65
                

                我初始化了 DOMDocument 以使其使用正確的編碼:

                I initialize the DOMDocument so it uses the correct encoding:

                $domDocument = new DOMDocument('1.0','UTF-8');
                

                當(dāng)我使用 mb_detect_encoding 檢查 saveXML() 的輸出時(shí),結(jié)果是 UTF-8.

                And when I check the output from saveXML() using mb_detect_encoding the result is UTF-8.

                我還檢查了用于創(chuàng)建 XML 的所有調(diào)用,對遇到的所有 createCDATASection 參數(shù)使用 mb_detect_encoding,它們都是 UTF-8 或 ASCII(沒有純文本節(jié)點(diǎn),所有內(nèi)容都在 CDATA 塊).

                I also checked all the calls used to create the XML, using mb_detect_encoding on all createCDATASection parameters encountered and they are all either UTF-8 or ASCII (there are no plain text nodes, everything is in CDATA blocks).

                我認(rèn)為問題來自于使用é"字符(在 ISO 8859-1).將該字符添加到我的 XML 的行是:

                I think the issue comes from the use of an 'é' character (which is 0xE9 in ISO 8859-1). The line which adds that character to my XML is:

                $domDocument->createCDATASection($place->name);
                

                和 mb_detect_encoding($place->name) 給我 UTF-8.

                and mb_detect_encoding($place->name) gives me UTF-8.

                數(shù)據(jù) ($place->name) 是從 MySQL 數(shù)據(jù)庫中提取的.此數(shù)據(jù)庫具有 UTF-8 字符集.

                The data ($place->name) is pulled from a MySQL database. This database has the UTF-8 charset.

                這是一些示例代碼:

                $query = sprintf('SELECT name FROM place where id = 1');
                $result = mysql_query($query);
                $result = mysql_fetch_assoc($result);
                
                
                // -- Feeding UTF-8 data directly WORKS
                $domDocument = new DOMDocument('1.0','UTF-8');
                $rootNode = $domDocument->createElement('Response');
                $rootNode->appendChild($domDocument->createCDATASection('Café Belga'));
                $domDocument->appendChild($rootNode);
                
                $matcher = array('tag' => 'Response');
                self::assertTag($matcher, $domDocument->saveXML(), '', FALSE);
                
                // -- Feeding UTF-8 data from the resultset FAILS
                $domDocument = new DOMDocument('1.0','UTF-8');
                $rootNode = $domDocument->createElement('Response');
                $rootNode->appendChild($domDocument->createCDATASection($result['name']));
                $domDocument->appendChild($rootNode);
                
                $matcher = array('tag' => 'Response');
                self::assertTag($matcher, $domDocument->saveXML(), '', FALSE);
                

                在我的 PHPStorm 調(diào)試器中,從數(shù)據(jù)庫中提取的字符串如下所示:

                In my PHPStorm debugger, the string fetched from the database looks like this:

                Café Belga

                所以我認(rèn)為這是問題的根源.在 MySQLWorkbench 中,字符串是正確的:Café Belga.

                So I think that is the root of the problem. In MySQLWorkbench the string is correct: Café Belga.

                使用 utf8_encode($result['name']) 時(shí),一切正常!

                When using utf8_encode($result['name']), however, everything works fine!

                在手表窗口中再檢查一次:

                One more check in the watches window:

                mb_detect_encoding($result['name']) -> "UTF-8"

                mb_detect_encoding($result['name']) -> "UTF-8"

                mb_detect_encoding(utf8_encode($result['name'])) -> "UTF-8"

                mb_detect_encoding(utf8_encode($result['name'])) -> "UTF-8"

                順便說一句,是否有任何網(wǎng)站可以讓我簡單地復(fù)制粘貼這些十六進(jìn)制值并查看它們在不同字符集中應(yīng)該是什么字符?

                On a side note, are there any sites where I can simply copy-paste those hex values and see what characters they are supposed to be in different character sets?

                推薦答案

                您必須將與數(shù)據(jù)庫的連接定義為 UTF-8:

                You have to define the connection to your database as UTF-8:

                // Set up your connection
                $connection = mysql_connect('localhost', 'user', 'pw');
                mysql_select_db('yourdb', $connection);
                mysql_query("SET NAMES 'utf8'", $connection);
                
                // Now you get UTF-8 encoded stuff
                $query = sprintf('SELECT name FROM place where id = 1');
                $result = mysql_query($query, $connection);
                $result = mysql_fetch_assoc($result);
                

                這篇關(guān)于如何讓 MySQL 返回 UTF-8?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                相關(guān)文檔推薦

                Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死鎖異常代碼?)
                PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滾動(dòng)游標(biāo)不起作用)
                PHP PDO ODBC connection(PHP PDO ODBC 連接)
                Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔術(shù)方法)
                php pdo get only one value from mysql; value that equals to variable(php pdo 只從 mysql 獲取一個(gè)值;等于變量的值)
                MSSQL PDO could not find driver(MSSQL PDO 找不到驅(qū)動(dòng)程序)
                <tfoot id='fBl5f'></tfoot>

                <small id='fBl5f'></small><noframes id='fBl5f'>

                  <legend id='fBl5f'><style id='fBl5f'><dir id='fBl5f'><q id='fBl5f'></q></dir></style></legend>
                      <tbody id='fBl5f'></tbody>
                  • <i id='fBl5f'><tr id='fBl5f'><dt id='fBl5f'><q id='fBl5f'><span id='fBl5f'><b id='fBl5f'><form id='fBl5f'><ins id='fBl5f'></ins><ul id='fBl5f'></ul><sub id='fBl5f'></sub></form><legend id='fBl5f'></legend><bdo id='fBl5f'><pre id='fBl5f'><center id='fBl5f'></center></pre></bdo></b><th id='fBl5f'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='fBl5f'><tfoot id='fBl5f'></tfoot><dl id='fBl5f'><fieldset id='fBl5f'></fieldset></dl></div>

                          <bdo id='fBl5f'></bdo><ul id='fBl5f'></ul>
                          主站蜘蛛池模板: 美女久久久久久久久 | 日韩中文字幕2019 | 亚洲一区免费视频 | 97精品超碰一区二区三区 | 亚洲欧美中文字幕 | 在线男人天堂 | 亚洲欧美日韩精品久久亚洲区 | 国产精品一区二区不卡 | 精品视频在线免费观看 | 日韩精品在线免费观看视频 | 黄色成人国产 | 欧美中文字幕在线观看 | 欧美影院 | 欧美视频网 | 国产精品视频一区二区三区 | 伊人免费在线观看 | 国产精品一区久久久 | 午夜免费在线 | 一区二区三区国产精品 | 久久小视频 | 久久一热| 亚洲精品www | 国产高清在线精品一区二区三区 | www.4虎影院 国产999精品久久久影片官网 | 国产99久久久国产精品 | 五月天婷婷狠狠 | 国产精品久久久久久久久 | 911影院 | 亚洲二区在线 | 国产91在线播放精品91 | 精品乱子伦一区二区三区 | 中文字幕av高清 | 中文字幕在线观看一区 | 久久com | av播播| 午夜在线免费观看视频 | 免费看欧美一级片 | 国产欧美视频一区二区 | a免费在线 | 亚洲精品3 | 欧美在线不卡 |