pg_pconnect

pg_pconnect

am 27.12.2002 10:09:02 von sector119

Hi

echo "\n";
$db = pg_pconnect("dbname=$dbname user=$user password=$dbpassword");
if (!$db)
echo "Connection can not be established!
\n";
else
echo "Connection established!
\n";
echo "
";
echo "";
?>

echo "\n";
if ($db)
echo "db handler is still valid!
\n";
else
echo "db handler does not exist anymore!
\n";
echo "";
?>


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

am 27.12.2002 10:16:32 von GOLDBERG

Not a problem with postgres or php : it is always stateless.

Le ven 27/12/2002 =E0 10:09, sector119@mail.ru a =E9crit :
> Hi
>=20
> > echo "\n";=20
> $db =3D pg_pconnect("dbname=3D$dbname user=3D$user password=3D$dbpassword=
");
> if (!$db)
> echo "Connection can not be established!
\n";
> else
> echo "Connection established!
\n";
> echo "
";
> echo "";
> ?>
>=20
> > echo "\n";=20
> if ($db)=20
> echo "db handler is still valid!
\n";=20
> else =2 0 =
=20
> echo "db handler does not exist anymore!
\n";=20
> echo "";
> ?>=20
>=20
>=20
> when I click on next screen link I get db handler does not exist anymore!=
why???=20
>=20
> --=20
> WBR, sector119
>=20
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>=20



---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

Re: pg_pconnect

am 28.12.2002 16:10:33 von brew

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 "\n";
> $db = pg_pconnect("dbname=$dbname user=$user password=$dbpassword");
> if (!$db)
> echo "Connection can not be established!
\n";
> else
> echo "Connection established!
\n";
> echo "
";
> echo "";
> ?>
>
> > echo "\n";
> if ($db)
> echo "db handler is still valid!
\n";
> else
> echo "db handler does not exist anymore!
\n";
> echo "";
> ?>
>
>



---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/users-lounge/docs/faq.html