开发者

PHP Constant open mysql connection safety?

I have a website where at the top of each page I include a page that opens a mysql_connect connection, so I don't have to open up the connection each time I need to modi开发者_开发知识库fy or insert stuff into the database. Is this safe, or should I open and close each connection once I'm done using it?

require_once("../include/mysqlconn.php");

$sql = "SELECT * FROM blah";
$query = mysql_query($sql);


This is OK as the connection will be closed automatically at the end of each script execution (actually all resources are freed at that point).

Another possibility is to use mysql_pconnect() which does connection caching for you and may speed up your site a bit.

In either case there is nothing to worry about security wise, as long as the password is kept in a place not accessible from outside.


Personally, I create a new connection each time I make a query, then close it. If you have multiple databases, you can clash if you leave it open.


well closing it is safer. you can also include a page that closes the connection to mysql at the end of every page you open the connection.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜