<bdo id='2vTMc'></bdo><ul id='2vTMc'></ul>
  • <legend id='2vTMc'><style id='2vTMc'><dir id='2vTMc'><q id='2vTMc'></q></dir></style></legend>

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

      1. <small id='2vTMc'></small><noframes id='2vTMc'>

        为什么在连接失败时 PDO 会打印我的密码?

        时间:2023-10-05
          <bdo id='qZ2F1'></bdo><ul id='qZ2F1'></ul>

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

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

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

                  <tbody id='qZ2F1'></tbody>

                  <tfoot id='qZ2F1'></tfoot>
                • 本文介绍了为什么在连接失败时 PDO 会打印我的密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有一个简单的网站,我在其中使用 PDO 建立到 MySQL 服务器的连接.

                  I have a simple website where I establish a connection to a MySQL server using PDO.

                  $dbh = new PDO('mysql:host=localhost;dbname=DB;port=3306',
                                 'USER',
                                 'SECRET', 
                                 array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
                  

                  我的网站上有一些流量并且达到了服务器的连接限制,网站抛出了这个错误,其中包含我的普通密码!

                  I had some traffic on my site and the server's connection limit was reached, and the website throws this error, with my plain password in it!

                  致命错误:未捕获的异常带有消息的PDOException"'SQLSTATE[08004] [1040] 太多连接'在/home/domain/html/index.php:xxx堆栈跟踪:#0/home/domain/html/index.php(64):PDO->__construct('mysql:host=loca...','用户'、'秘密'、数组)#1{main} 投入/home/domain/html/index.php 上第 64 行

                  Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[08004] [1040] Too many connections' in /home/domain/html/index.php:xxx Stack trace: #0 /home/domain/html/index.php(64): PDO->__construct('mysql:host=loca...', 'USER', 'SECRET', Array) #1 {main} thrown in /home/domain/html/index.php on line 64

                  具有讽刺意味的是,我出于安全原因切换到 PDO,所以这真的让我感到震惊,因为在大多数使用简单 HTTP 泛洪的网站上,您可以很容易地引发这个确切的错误.

                  Ironically I switched to PDO for security reasons, so this really shocked me, because this exact error is something you can provoke very easily on most sites using simple HTTP flooding.

                  我现在已经将我的连接包裹在一个 try/catch 块中,但我仍然认为这是灾难性的!

                  I have now wrapped my connection in a try/catch block, but still I think this is catastrophic!

                  我是 PDO 的新手,所以我的问题是:我必须做什么才能确保安全?如何以安全的方式建立连接?是否还有其他已知的安全漏洞需要我注意?

                  I am new to PDO and so my question is: what do I have to do to consider to be safe? How do I establish a connection in a secure way? Are there other known security holes like this one that I have to be aware of?

                  推荐答案

                  无论如何,您都应该在 PHP.ini 中设置 display_errors = off 以避免此问题.除了 PDO 之外,显示此类详细信息的错误还来自许多地方.

                  You should have display_errors = off in your PHP.ini anyway to avoid this problem. Errors that reveal details like these come from many places, in addition to PDO.

                  是的,您也应该将它放在 try/catch 块中.

                  Yes, you should also have it in a try/catch block.

                  您也可以$pdo->setAttribute(PDO::ERRMODE_SILENT),但是您需要手动检查错误代码而不是使用 try/catch 块.请参阅http://php.net/manual/en/pdo.setattribute.php 获取更多错误常量.

                  You can also $pdo->setAttribute(PDO::ERRMODE_SILENT), but then you need to be checking the error codes manually rather than using a try/catch block. See http://php.net/manual/en/pdo.setattribute.php for more error constants.

                  这篇关于为什么在连接失败时 PDO 会打印我的密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:PDO fetch 只返回第一行 下一篇:PHP 7.2.2 + mysql 8.0 PDO 给出:客户端未知的身份验证

                  相关文章

                  最新文章

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

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

                      <legend id='A0GhP'><style id='A0GhP'><dir id='A0GhP'><q id='A0GhP'></q></dir></style></legend>
                      <tfoot id='A0GhP'></tfoot>