PHP/MySQL: Create new connection for each query?(PHP/MySQL:为每个查询创建新连接?)
问题描述
我有一个包含一些 mysql 查询的网页,我必须在每次查询后启动新的数据库连接并关闭数据库,或者更有效地在代码顶部启动一个数据库连接并在脚本底部关闭?谢谢!
I have a webpage with some mysql querys, I must start new db connection and db close after every query or its more efficiently start an only one db connection at the top of the code and close at the bottom of the script? Thanks!
推荐答案
从不为每个查询创建新连接;这非常浪费,并且会使您的 MySQL 服务器负担过重.
Never create a new connection for every query; it's very wasteful and will overburden your MySQL server.
在脚本顶部创建一个连接就足够了 - 所有后续查询都将使用该连接,直到页面结束.您甚至可以在将 include()
编入脚本的其他脚本中使用该连接,并在其中调用 mysql_connect()
.
Creating one connection at the top of your script is enough - all subsequent queries will use that connection until the end of the page. You can even use that connection in other scripts that are include()
ed into the script with your mysql_connect()
call in it.
这篇关于PHP/MySQL:为每个查询创建新连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PHP/MySQL:为每个查询创建新连接?


- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- SoapClient 设置自定义 HTTP Header 2021-01-01
- 正确分离 PHP 中的逻辑/样式 2021-01-01
- 带有通配符的 Laravel 验证器 2021-01-01
- Mod使用GET变量将子域重写为PHP 2021-01-01
- 如何定位 php.ini 文件 (xampp) 2022-01-01
- PHP Count 布尔数组中真值的数量 2021-01-01
- Laravel 仓库 2022-01-01
- 没有作曲家的 PSR4 自动加载 2022-01-01
- 从 PHP 中的输入表单获取日期 2022-01-01