跨页面保持数据库连接活动 [英] keeping db connection active across pages

查看:82
本文介绍了跨页面保持数据库连接活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个学习者.当用户被带到下一页时,有没有办法保持与mysql数据库的连接.

I'm a learner. Is there a way to stay connected in to the mysql database as the user is taken to the next page.

例如,建立db连接,用户登录,然后转到下一页以访问数据库中的表.不必再次建立数据库连接,有没有办法使先前的连接保持活动状态?

For example, the db connection is made, the user is logged in, and then goes to the next page to access a table in the database. Instead of having to make the db connection again, is there a way to keep the previous connection active?

还是在人流少的网站上有关系吗?

Or does it matter at all in a low-traffic site?

昨天我读了一篇有关会话的文章,响应者谈到要发送标头类型"(?)文件.

I read a post yesterday about something related to sessions, and the responder talked about sending a "header-type" (?) file.

谢谢.

推荐答案

是,不是.用户转到下一页后,出于所有意图和目的,他们不再连接到数据库.

Yes and no. Once the user goes to the next page, for all intents and purposes they are not connected to the database anymore.

您的脚本(在下一页上)仍然需要为它们打开连接. mysql_pconnect()将确保他们使用的实际连接在下次需要时仍然可用,但是,这也会导致过多的apache/mysql连接无用地等待.

Your script (on the next page) will still need to open the connection for them. mysql_pconnect() will ensure the actual connection they used is still available when they want it next, however, it can also cause excess number of apache/mysql connections to wait around uselessly.

我强烈建议您不要使用它,除非您的基准测试表明它可以显着提高性能.通常,对于大多数应用程序(尤其是在学习时),我不会为持久连接而烦恼.请注意 PHP手册

I'd strongly suggest not using it unless your benchmarks show that it provides a significant gain in performance. Typically, for most applications (especially when you're learning), I would not bother with persistent connections. Note the warning in the PHP Manual

这篇关于跨页面保持数据库连接活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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