• <small id='zaU0Z'></small><noframes id='zaU0Z'>

      • <bdo id='zaU0Z'></bdo><ul id='zaU0Z'></ul>

    1. <legend id='zaU0Z'><style id='zaU0Z'><dir id='zaU0Z'><q id='zaU0Z'></q></dir></style></legend>
      <tfoot id='zaU0Z'></tfoot>
    2. <i id='zaU0Z'><tr id='zaU0Z'><dt id='zaU0Z'><q id='zaU0Z'><span id='zaU0Z'><b id='zaU0Z'><form id='zaU0Z'><ins id='zaU0Z'></ins><ul id='zaU0Z'></ul><sub id='zaU0Z'></sub></form><legend id='zaU0Z'></legend><bdo id='zaU0Z'><pre id='zaU0Z'><center id='zaU0Z'></center></pre></bdo></b><th id='zaU0Z'></th></span></q></dt></tr></i><div id='zaU0Z'><tfoot id='zaU0Z'></tfoot><dl id='zaU0Z'><fieldset id='zaU0Z'></fieldset></dl></div>

        PDO UTF-8 编码问题?

        时间:2023-10-04

        <small id='3tFhm'></small><noframes id='3tFhm'>

        <legend id='3tFhm'><style id='3tFhm'><dir id='3tFhm'><q id='3tFhm'></q></dir></style></legend>
      1. <i id='3tFhm'><tr id='3tFhm'><dt id='3tFhm'><q id='3tFhm'><span id='3tFhm'><b id='3tFhm'><form id='3tFhm'><ins id='3tFhm'></ins><ul id='3tFhm'></ul><sub id='3tFhm'></sub></form><legend id='3tFhm'></legend><bdo id='3tFhm'><pre id='3tFhm'><center id='3tFhm'></center></pre></bdo></b><th id='3tFhm'></th></span></q></dt></tr></i><div id='3tFhm'><tfoot id='3tFhm'></tfoot><dl id='3tFhm'><fieldset id='3tFhm'></fieldset></dl></div>
          • <bdo id='3tFhm'></bdo><ul id='3tFhm'></ul>

            1. <tfoot id='3tFhm'></tfoot>
                <tbody id='3tFhm'></tbody>

                  本文介绍了PDO UTF-8 编码问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我使用 PDO 连接到 MYSQL 数据库

                  i am using PDO for connecting to MYSQL database

                  数据库中的所有表都有utf8_unicode_ci整理

                  all tables in database have utf8_unicode_ci Collation

                  这是我的连接代码:

                  <?php
                  $mysql_username = "root";
                  $mysql_password = "";
                  $mysql_host = "localhost";
                  $mysql_database = "cms";
                  
                  try
                  {
                      //connect
                      global $db;
                      $db = new PDO('mysql:dbname=' . $mysql_database . ';host=' . $mysql_host . ';charset=utf8;', $mysql_username, $mysql_password);
                      $db->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, 'SET NAMES utf8');
                      $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
                      $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
                  }
                  catch(PDOException $ex)
                  {
                      die("Unable Connect To DataBase");
                  }
                  ?>
                  

                  在本地主机中,我对编码没有问题,但是当我将源上传到主机时,我看到的是 ?????? 而不是字符?

                  in localhost i have no problem with encoding but when i uploaded the source to a host i see ?????? instead of characters?

                  推荐答案

                  这个:

                  $db->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, 'SET NAMES utf8');
                  

                  完全没有意义.见http://php.net/manual/en/ref.pdo-mysql.php.MYSQL_ATTR_INIT_COMMAND 在连接建立后立即执行,不会稍后执行.如果您在已经完全创建的 PDO 对象上设置它,则为时已晚,它永远不会执行.您需要将其传递给构造函数:

                  is entirely pointless. See http://php.net/manual/en/ref.pdo-mysql.php. The MYSQL_ATTR_INIT_COMMAND is executed right after the connection is established, no later. If you set this on an already fully created PDO object, it's too late and it never executes. You need to pass it to the constructor:

                  new PDO(..., ..., ..., array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'))
                  

                  或者,如果您的 PHP 版本支持,请将 charset=utf8 添加到 DSN.

                  Alternatively, if your PHP version supports it, add charset=utf8 to the DSN.

                  这篇关于PDO UTF-8 编码问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:我可以在 Laravel 中集成自定义 PDO 包装器吗 下一篇:带 PDO 的多个刀片

                  相关文章

                  最新文章

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

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

                        <bdo id='RmSSC'></bdo><ul id='RmSSC'></ul>
                    1. <legend id='RmSSC'><style id='RmSSC'><dir id='RmSSC'><q id='RmSSC'></q></dir></style></legend>
                      <tfoot id='RmSSC'></tfoot>