Обсуждение: pg_pconnect

Поиск
Список
Период
Сортировка

pg_pconnect

От
sector119@mail.ru
Дата:
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>";
?>


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

--
WBR, sector119

Re: pg_pconnect

От
GOLDBERG
Дата:
Not a problem with postgres or php : it is always stateless.

Le ven 27/12/2002 à 10:09, sector119@mail.ru a écrit :
> 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>";
> ?>
>
>
> when I click on next screen link I get db handler does not exist anymore! why???
>
> --
> WBR, sector119
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>



Re: pg_pconnect

От
brew@theMode.com
Дата:
On Fri, 27 Dec 2002 sector119@mail.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>";
> ?>
>
>