English 中文(简体)
将数据库连接到一个届会变量[复制]
原标题:Storing database connection in a session variable [duplicate]
This question already has answers here:
Closed 10 years ago.

Possible Duplicate:
Can t pass mysqli connection in session in php

我们当中有许多人撰写了需要数据库的PHP应用程序;多半是MySQL,但我常常使用非常小的MS接入数据库,为那些技术上能力较差的人提供这种数据库,以便他们能够自己下载一个拖网(无论是否正确,我没有想法)。

我注意到的是,许多时间用于连接和处理一些同样的问题。 由于这个原因,我有一个有趣的想法: 堵塞连接和可能的成果套,这些连接和套件大多在<代码>_SESSION变量中固定,以减轻用户在现场航行的负担。

显然,这样做需要很多考虑。 届会被毁时关闭联系等事情只是开端。

My question boils down to: Is this really something possible? And if so, what things should I be aware of (besides session fixation, as it is its own problem that applies to all sessions)?

最佳回答

即使你能够这样做(资源与数据),这是坏的想法。 你用大量同时开放的连接冲破,将非常快地打击你的最大联系......特别是如果其生命周期扩展到100米以下(取决于你的询问)到20分钟或20分钟以上。 在开放的连接下,像我的SQL一样,也未能适当重新确定其记忆分配,整个系统都会遭受损失。 简言之,这并不是行所要做的事,除非贵法典的唯一消费者是单一用户。

作为替代办法,我高度建议专门设计的沥滤技术,以减少数据库的负荷和连接时间。 利用像这样的东西,最简单地说,可大大改善周围的绩效,而你则能够确切地说明系统有多少资源流向海滩——同时让数据库在需要时尽力获取数据。

问题回答

您可以储存数据库链接或会议成果集,因为resources;

Some types of data can not be serialized thus stored in sessions. It includes resource variables or objects with circular references (i.e. objects which passes a reference to itself to another object).

http://php.net/manual/en/intro.session.php> rel=“noreferer”> http://php.net/manual/en/intro.session.php

你们可以把结果排入正常的阵列,并储存在本届会议上与任何其他变量一样。 这对会议来说是一个相当典型的使用案例。 谨慎行事,不要在本届会议中储存太多的数据,因为这比从数据库中抽取更多的税收。

You can check permanent connections for the connection part. http://php.net/manual/en/function.mysql-pconnect.php

你们应该让某些编织物的人得到更好的使用。 会议是专门会议,而不是全球会议。





相关问题
what is wrong with this mysql code

$db_user="root"; $db_host="localhost"; $db_password="root"; $db_name = "fayer"; $conn = mysqli_connect($db_host,$db_user,$db_password,$db_name) or die ("couldn t connect to server"); // perform query ...

Users asking for denormalized database

I am in the early stages of developing a database-driven system and the largest part of the system revolves around an inheritance type of relationship. There is a parent entity with about 10 columns ...

Easiest way to deal with sample data in Java web apps?

I m writing a Java web app in my free time to learn more about development. I m using the Stripes framework and eventually intend to use hibernate and MySQL For the moment, whilst creating the pages ...

join across databases with nhibernate

I am trying to join two tables that reside in two different databases. Every time, I try to join I get the following error: An association from the table xxx refers to an unmapped class. If the ...

How can I know if such value exists in database? (ADO.NET)

For example, I have a table, and there is a column named Tags . I want to know if value programming exists in this column. How can I do this in ADO.NET? I did this: OleDbCommand cmd = new ...

Convert date to string upon saving a doctrine record

I m trying to migrate one of my PHP projects to Doctrine. I ve never used it before so there are a few things I don t understand. In my current code, I have a class similar to this: class ...

热门标签