pg.ddx.io pgsql-php@postgresql.org mailing list archive
help / color / mirror / Atom feeddb connections in session variables
3+ messages / 3 participants
[nested] [flat]
* db connections in session variables
@ 2001-11-13 20:36 Timothy_Maguire@hartehanks.com
0 siblings, 1 reply; 3+ messages in thread
From: Timothy_Maguire@hartehanks.com @ 2001-11-13 20:36 UTC (permalink / raw)
To: pgsql-php
I was wondering if it were possible to store a database connection in a
session variable.
I have tried these 2 methods:
$conn = pg_pconnect("server", "5432", "db");
session_start();
session_register('conn');
$conn = pg_pconnect("server", "5432", "db");
session_id($conn);
session_start();
both of them register a session with the value of "Resource id #1" but
don't act as a db connection. I am just trying to clean up some code so I
don't have to do a new database connection on every page that I create.
Then if you are able to do this, where would you close the connection?
I guess in ASP, it is possible to store db connections in a session
variable. I have never done it there either but someone told me that you
can.
Tim.
Timothy P. Maguire
Web Developer II
Harte-Hanks
978 436 3325
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: db connections in session variables
@ 2001-11-13 21:49 Martín Marqués <martin@bugs.unl.edu.ar>
parent: Timothy_Maguire@hartehanks.com
0 siblings, 1 reply; 3+ messages in thread
From: Martín Marqués @ 2001-11-13 21:49 UTC (permalink / raw)
To: pgsql-php
On Mar 13 Nov 2001 17:36, you wrote:
> I was wondering if it were possible to store a database connection in a
> session variable.
No! Because the persistent connection gets opened with one child, and when
you go for the next page you have very high probabilities (unless you have a
very poor http configuration) of caching a new child, and not the old one.
The problem comes here, just because the pconnect was done against the old
child, and the new one doesn't know a thing about the pconnect you did
before, so you'll allways (or almost always) an error of "wrong connection
id".
Hope I was clear.
> I have tried these 2 methods:
>
> $conn = pg_pconnect("server", "5432", "db");
> session_start();
> session_register('conn');
>
> $conn = pg_pconnect("server", "5432", "db");
> session_id($conn);
> session_start();
>
> both of them register a session with the value of "Resource id #1" but
> don't act as a db connection. I am just trying to clean up some code so I
> don't have to do a new database connection on every page that I create.
>
> Then if you are able to do this, where would you close the connection?
>
> I guess in ASP, it is possible to store db connections in a session
> variable. I have never done it there either but someone told me that you
> can.
>
> Tim.
>
> Timothy P. Maguire
> Web Developer II
> Harte-Hanks
> 978 436 3325
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org
--
Porqué usar una base de datos relacional cualquiera,
si podés usar PostgreSQL?
-----------------------------------------------------------------
Martín Marqués | mmarques@unl.edu.ar
Programador, Administrador, DBA | Centro de Telematica
Universidad Nacional
del Litoral
-----------------------------------------------------------------
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: db connections in session variables
@ 2001-11-14 09:53 Papp Gyozo <pgerzson@freestart.hu>
parent: Martín Marqués <martin@bugs.unl.edu.ar>
0 siblings, 0 replies; 3+ messages in thread
From: Papp Gyozo @ 2001-11-14 09:53 UTC (permalink / raw)
To: pgsql-php
Beside this overwhelming description, PHP manual states it somewhere, but
I can't recall it exactly where.
Oooh, what fool me! it was discussed in session_register section:
(http://www.php.net/manual/en/function.session-register.php)
"Note: It is not currently possible to register resource variables in a session. For example, you can not create a connection to a database and store the connection id as a session variable and expect the connection to still be valid the next time the session is restored. PHP functions that return a resource are identified by having a return type of resource in their function definitions. A list of functions that return resources are available in the resource types appendix."
BTW, when I worte my first PHP code, this note had not been added yet,
and I also tried to register resources.
----- Original Message -----
From: "Martín Marqués" <martin@bugs.unl.edu.ar>
To: <pgsql-php@postgresql.org>
Sent: Tuesday, November 13, 2001 10:49 PM
Subject: Re: [PHP] db connections in session variables
On Mar 13 Nov 2001 17:36, you wrote:
> I was wondering if it were possible to store a database connection in a
> session variable.
No! Because the persistent connection gets opened with one child, and when
you go for the next page you have very high probabilities (unless you have a
very poor http configuration) of caching a new child, and not the old one.
The problem comes here, just because the pconnect was done against the old
child, and the new one doesn't know a thing about the pconnect you did
before, so you'll allways (or almost always) an error of "wrong connection
id".
Hope I was clear.
> I have tried these 2 methods:
>
> $conn = pg_pconnect("server", "5432", "db");
> session_start();
> session_register('conn');
>
> $conn = pg_pconnect("server", "5432", "db");
> session_id($conn);
> session_start();
>
> both of them register a session with the value of "Resource id #1" but
> don't act as a db connection. I am just trying to clean up some code so I
> don't have to do a new database connection on every page that I create.
>
> Then if you are able to do this, where would you close the connection?
>
> I guess in ASP, it is possible to store db connections in a session
> variable. I have never done it there either but someone told me that you
> can.
>
> Tim.
>
> Timothy P. Maguire
> Web Developer II
> Harte-Hanks
> 978 436 3325
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org
--
Porqué usar una base de datos relacional cualquiera,
si podés usar PostgreSQL?
-----------------------------------------------------------------
Martín Marqués | mmarques@unl.edu.ar
Programador, Administrador, DBA | Centro de Telematica
Universidad Nacional
del Litoral
-----------------------------------------------------------------
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2001-11-14 09:53 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-11-13 20:36 db connections in session variables Timothy_Maguire@hartehanks.com
2001-11-13 21:49 ` Martín Marqués <martin@bugs.unl.edu.ar>
2001-11-14 09:53 ` Papp Gyozo <pgerzson@freestart.hu>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox