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

  1. <tfoot id='Fb5nH'></tfoot>

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

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

      从 mysql_connect() 获取 PHP PDO 连接?

      时间:2023-09-19
    1. <small id='eFXOQ'></small><noframes id='eFXOQ'>

        <tbody id='eFXOQ'></tbody>

        • <legend id='eFXOQ'><style id='eFXOQ'><dir id='eFXOQ'><q id='eFXOQ'></q></dir></style></legend>

          <tfoot id='eFXOQ'></tfoot>

          1. <i id='eFXOQ'><tr id='eFXOQ'><dt id='eFXOQ'><q id='eFXOQ'><span id='eFXOQ'><b id='eFXOQ'><form id='eFXOQ'><ins id='eFXOQ'></ins><ul id='eFXOQ'></ul><sub id='eFXOQ'></sub></form><legend id='eFXOQ'></legend><bdo id='eFXOQ'><pre id='eFXOQ'><center id='eFXOQ'></center></pre></bdo></b><th id='eFXOQ'></th></span></q></dt></tr></i><div id='eFXOQ'><tfoot id='eFXOQ'></tfoot><dl id='eFXOQ'><fieldset id='eFXOQ'></fieldset></dl></div>
            • <bdo id='eFXOQ'></bdo><ul id='eFXOQ'></ul>
              1. 本文介绍了从 mysql_connect() 获取 PHP PDO 连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我有一个旧的 PHP/MySQL 应用程序,它调用 mysql_connect().大量现有的下游代码使用此连接直接或通过包装器进行 mysql_query() 调用.

                I have a legacy PHP/MySQL app that calls mysql_connect(). Tons of existing downstream code makes mysql_query() calls, either directly or through wrappers, using this connection.

                对于我在应用程序上开发的新代码,我想开始使用 PDO.

                For new code that I develop on the app, I would like to start using PDO.

                如果我使用相同的主机/用户/密码/dbname 凭据建立 PDO 连接,我是否很幸运,在幕后,PHP 将重新使用原始连接?或者 PHP 是否会创建到服务器的两个不同的连接(不合需要,尽管完全可以理解)?

                If I make a PDO connection using the same host/user/pass/dbname credentials, might I be so lucky that under the hood, PHP will re-use the original connection? Or will PHP create two distinct connections to the server (undesirable, albeit totally understandable)?

                谢谢!

                推荐答案

                如果您使用两个不同的 API(即 mysql_* 和 PDO),PHP 将生成两个不同的连接.

                If you are using two different APIs (i.e. mysql_* and PDO), PHP will generate two different connections.


                并且,作为证明",请考虑这部分代码:


                And, as a "proof", consider this portion of code :

                $db = mysql_connect('localhost', 'USER', 'PASSWORD');
                $pdo = new PDO('mysql://@localhost/astralblog', 'USER', 'PASSWORD');
                sleep(5);
                


                运行这将在 MySQL 服务器上产生两个不同的连接——它将休眠 5 秒:


                Running this will cause two distinct connections, on the MySQL server -- which will sleep for 5 seconds :

                mysql> show processlist;
                +----+------------+-----------------+------------+---------+------+-------+------------------+
                | Id | User       | Host            | db         | Command | Time | State | Info             |
                +----+------------+-----------------+------------+---------+------+-------+------------------+
                | 41 | astralblog | localhost:46551 | astralblog | Sleep   |  188 |       | NULL             |
                | 42 | astralblog | localhost:46552 | astralblog | Sleep   |  188 |       | NULL             |
                | 43 | astralblog | localhost       | astralblog | Query   |    0 | NULL  | show processlist |
                | 64 | astralblog | localhost       | NULL       | Sleep   |    4 |       | NULL             |
                | 65 | astralblog | localhost       | NULL       | Sleep   |    4 |       | NULL             |
                +----+------------+-----------------+------------+---------+------+-------+------------------+
                5 rows in set (0,00 sec)
                

                (有问题的连接是最后两个,在我启动PHP脚本时出现,5秒后消失)

                这篇关于从 mysql_connect() 获取 PHP PDO 连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:尝试访问 bool 类型值的数组偏移量 下一篇:使用 PDO 设置连接超时

                相关文章

                最新文章

                <small id='2SFLW'></small><noframes id='2SFLW'>

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

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