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

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

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

      2. 我应该什么时候关闭 PHP 中的数据库连接?

        时间:2023-07-30

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

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

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

                • 本文介绍了我应该什么时候关闭 PHP 中的数据库连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我不像 php 开发人员,但我必须使用它,而且我并不真正了解 PHP 如何在会话期间处理内存分配.

                  I'm nothing like a php developer but I do have to use it and I'm not really aware on how PHP handle memory allocation during session.

                  我正在开发一个要求 HTTP 身份验证的应用程序,一旦您登录,您就可以通过一个漂亮的界面操作数据.
                  有人在另一篇文章中告诉我,我不应该在每次执行后关闭 mysql 数据连接,但我不知道在使用这个应用程序期间这个连接是如何保持内存的,因为在服务器端我不知道 PHP 保留了什么记忆与否.

                  I'm working on an application that ask for an HTTP authentication, once you're logged in you can manipulate data through a nice interface.
                  Someone told me on another post, that I shouldn't close the mysql data connection after every execution, but I don't know how this connection stay is memory during using this app because in the server side I have no idea what PHP keeps in memory or not.

                  所以我的问题是我应该使用单例连接到数据库并且永​​远不要关闭它(因为我永远不会知道应用程序何时不在使用中.或者我应该坚持我今天所做的:打开连接-->执行语句 --> 关闭连接.

                  So my question is should I use a singleton to connect to the db and never close it (because I will never know when the application is not in use. Or should I stand with what I do today: opening connection --> execute statement --> close connection.

                  PS:我正在使用 mysqli

                  PS: I'm using mysqli

                  编辑 1:
                  我的应用程序是用 MVC 模式设计的,意思是:

                  Edit 1:
                  My application is design with MVC pattern meaning :

                  |''''''''''|      |'''''''''''''|      |''''''''''''''|
                  | view.php |  ==> | control.php |  ==> | database.php |
                  |----------|      |_____________|      |______________|
                  

                  该模式允许视图仅通过 control.php 与数据交互,然后从 database.php 调用函数到 SELECTEDIT数据.根据你给我的解释,我应该说:

                  That pattern allow the view to interact with data only through the control.php which then call a function from database.php to SELECT or EDIT data. with the explanation you give me, I should put:

                  public function __destruct(){
                      mysql_close($this->connection);
                  }
                  

                  database.php中,但是当需要选择或修改数据时加载该页面,所以它只执行很短的时间,这意味着它仍然会在结束时关闭连接请求.

                  inside database.php, but that page is load when there's a need to select or modify data, so it's only executed for a short time, meaning it will still close the connection at the end of the request.

                  哪个给出了一个更精确的问题,即我应该将您提供的代码放在哪里,或者我的模式是否与 PHP 相关?

                  Which gives a more precise question of where should I put the peace of code you provide, or does my pattern relevant in PHP ?

                  推荐答案

                  永远不要为每个查询都创建一个新的连接;您甚至不必手动关闭它.

                  Never create a new connection for every query; You don't even have to close it manually.

                  只需在页面开头创建连接

                  Just create the connection at the beginning of you page

                  看看:你如何在 php 中有效地连接到 mysql 而无需在每次查询时重新连接

                  你可以使用这个:

                  public function __destruct()
                  {
                     mysql_close($this->connection);
                  }
                  

                  页面关闭时调用

                  这篇关于我应该什么时候关闭 PHP 中的数据库连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                      <legend id='DjLdC'><style id='DjLdC'><dir id='DjLdC'><q id='DjLdC'></q></dir></style></legend>
                      1. <small id='DjLdC'></small><noframes id='DjLdC'>

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