PHP/MySQL:为每个查询创建新连接? [英] PHP/MySQL: Create new connection for each query?

查看:31
本文介绍了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:为每个查询创建新连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆