pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

<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="qwoei2i" 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="coaa2ue" 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?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

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

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

                當我使用 mb_detect_encoding 檢查 saveXML() 的輸出時,結果是 UTF-8.

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

                我還檢查了用于創建 XML 的所有調用,對遇到的所有 createCDATASection 參數使用 mb_detect_encoding,它們都是 UTF-8 或 ASCII(沒有純文本節點,所有內容都在 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).

                我認為問題來自于使用é"字符(在 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.

                數據 ($place->name) 是從 MySQL 數據庫中提取的.此數據庫具有 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 調試器中,從數據庫中提取的字符串如下所示:

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

                Café Belga

                所以我認為這是問題的根源.在 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']) 時,一切正常!

                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"

                順便說一句,是否有任何網站可以讓我簡單地復制粘貼這些十六進制值并查看它們在不同字符集中應該是什么字符?

                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?

                推薦答案

                您必須將與數據庫的連接定義為 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);
                

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

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

                相關文檔推薦

                Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死鎖異常代碼?)
                PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滾動游標不起作用)
                PHP PDO ODBC connection(PHP PDO ODBC 連接)
                Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔術方法)
                php pdo get only one value from mysql; value that equals to variable(php pdo 只從 mysql 獲取一個值;等于變量的值)
                MSSQL PDO could not find driver(MSSQL PDO 找不到驅動程序)
                <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="0gcayek" id='fBl5f'><tfoot id='fBl5f'></tfoot><dl id='fBl5f'><fieldset id='fBl5f'></fieldset></dl></div>

                          <bdo id='fBl5f'></bdo><ul id='fBl5f'></ul>
                          主站蜘蛛池模板: 刮板输送机,粉尘加湿搅拌机,螺旋输送机,布袋除尘器 | 广东机电安装工程_中央空调工程_东莞装饰装修-广东粤标建设有限公司 | ISO9001认证咨询_iso9001企业认证代理机构_14001|18001|16949|50430认证-艾世欧认证网 | 电机保护器-电动机综合保护器-上海硕吉电器有限公司 | 专业广州网站建设,微信小程序开发,一物一码和NFC应用开发、物联网、外贸商城、定制系统和APP开发【致茂网络】 | 影像测量仪_三坐标测量机_一键式二次元_全自动影像测量仪-广东妙机精密科技股份有限公司 | 热镀锌槽钢|角钢|工字钢|圆钢|H型钢|扁钢|花纹板-天津千百顺钢铁贸易有限公司 | 废旧物资回收公司_广州废旧设备回收_报废设备物资回收-益美工厂设备回收公司 | 贴片电容代理-三星电容-村田电容-风华电容-国巨电容-深圳市昂洋科技有限公司 | 电表箱-浙江迈峰电力设备有限公司-电表箱专业制造商 | 心肺复苏模拟人|医学模型|急救护理模型|医学教学模型上海康人医学仪器设备有限公司 | 南京试剂|化学试剂|分析试剂|实验试剂|cas号查询-专业60年试剂销售企业 | 专业的压球机生产线及解决方案厂家-河南腾达机械厂 | 贴片电感_贴片功率电感_贴片绕线电感_深圳市百斯特电子有限公司 贴片电容代理-三星电容-村田电容-风华电容-国巨电容-深圳市昂洋科技有限公司 | 液压升降平台_剪叉式液压/导轨式升降机_传菜机定做「宁波日腾升降机厂家」 | 阜阳在线-阜阳综合门户| 5L旋转蒸发器-20L-50L旋转蒸发器-上海越众仪器设备有限公司 | 没斑啦-专业的祛斑美白嫩肤知识网站-去斑经验分享 | 大型工业风扇_工业大风扇_大吊扇_厂房车间降温-合昌大风扇 | 电销卡_稳定企业大语音卡-归属地可选-世纪通信 | 企典软件一站式企业管理平台,可私有、本地化部署!在线CRM客户关系管理系统|移动办公OA管理系统|HR人事管理系统|人力 | STRO|DTRO-STRO反渗透膜(科普)_碟滤 | 儋州在线-儋州招聘找工作、找房子、找对象,儋州综合生活信息门户! | 拉伸膜,PE缠绕膜,打包带,封箱胶带,包装膜厂家-东莞宏展包装 | 半自动预灌装机,卡式瓶灌装机,注射器灌装机,给药器灌装机,大输液灌装机,西林瓶灌装机-长沙一星制药机械有限公司 | 英思科GTD-3000EX(美国英思科气体检测仪MX4MX6)百科-北京嘉华众信科技有限公司 | 建筑工程资质合作-工程资质加盟分公司-建筑资质加盟 | 医院专用门厂家报价-医用病房门尺寸大全-抗菌木门品牌推荐 | ASA膜,ASA共挤料,篷布色母料-青岛未来化学有限公司 | 阻垢剂,反渗透阻垢剂,缓蚀阻垢剂-山东普尼奥水处理科技有限公司 真空粉体取样阀,电动楔式闸阀,电动针型阀-耐苛尔(上海)自动化仪表有限公司 | 磁力轮,磁力联轴器,磁齿轮,钕铁硼磁铁-北京磁运达厂家 | 杭州代理记账多少钱-注册公司代办-公司注销流程及费用-杭州福道财务管理咨询有限公司 | 谈股票-今日股票行情走势分析-牛股推荐排行榜 | AGV无人叉车_激光叉车AGV_仓储AGV小车_AGV无人搬运车-南昌IKV机器人有限公司[官网] | 南京技嘉环保科技有限公司-杀菌除臭剂|污水|垃圾|厕所|橡胶厂|化工厂|铸造厂除臭剂 | 氧氮氢联合测定仪-联测仪-氧氮氢元素分析仪-江苏品彦光电 | 高低温试验箱-模拟高低温试验箱订制-北京普桑达仪器科技有限公司【官网】 | 智能化的检漏仪_气密性测试仪_流量测试仪_流阻阻力测试仪_呼吸管快速检漏仪_连接器防水测试仪_车载镜头测试仪_奥图自动化科技 | 德州网站制作 - 网站建设设计 - seo排名优化 -「两山建站」 | 广东风淋室_广东风淋室厂家_广东风淋室价格_广州开源_传递窗_FFU-广州开源净化科技有限公司 | 圈酒招商网【jiushuitv.com】_酒水招商_代理_加盟平台 |