Re: pg_pconnect

From: brew(at)theMode(dot)com
To: pgsql-php(at)postgresql(dot)org
Subject: Re: pg_pconnect
Date: 2002-12-28 15:10:33
Message-ID: Pine.BSF.4.44.0212280948590.8607-100000@themode.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-php


On Fri, 27 Dec 2002 sector119(at)mail(dot)ru wrote:

> when I click on next screen link I get db handler does not exist
> anymore! why???

The db handle is only a variable that points at the persistent connection.
Although the database connection is persistent (that is, remains after the
a php script completes) the db handle variable goes away.

You have to again call the pg_pconnect() function before using it in a
following script.

A persistent database connection does not save web page state, the only
thing it does is leave the pipe connected between the web server and the
database server, thereby saving the time of establishing a new connection.
The only benefit is speed.

You mostly write the PHP script exactly the same using either pg_pconnect
or pg_connect (except you have to be careful of hanging transactions
tieing up your persistent connections). I think you would be better off
using pg_connect for development and consider changing to persistent
connections later.

Read Chapter 21 in the manual at php.net entitled Persistent Database
Connections.

later.... brew

> Hi
>
> <?
> echo "<html><body>\n";
> $db = pg_pconnect("dbname=$dbname user=$user password=$dbpassword");
> if (!$db)
> echo "Connection can not be established!<br>\n";
> else
> echo "Connection established!<br>\n";
> echo "<a href=\"cursor4.php\">next screen</a><br>";
> echo "</body></html>";
> ?>
>
> <?
> echo "<html><body>\n";
> if ($db)
> echo "db handler is still valid!<br>\n";
> else
> echo "db handler does not exist anymore!<br>\n";
> echo "</body></html>";
> ?>
>
>

In response to

Browse pgsql-php by date

  From Date Subject
Next Message Dan Langille 2002-12-30 21:26:16 any web hosting recommendations?
Previous Message GOLDBERG 2002-12-27 09:16:32 Re: pg_pconnect