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

查看:108
本文介绍了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.

在脚本顶部创建一个连接就足够了-所有后续查询将使用该连接,直到页面末尾.您甚至可以在调用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天全站免登陆