I think you're misunderstanding what include actually does.

Let's say we have a file called db.php, with the contents:

<?php
$conn = pg_connect();
?>

Now, if the contents of your other script are:

<?php
include (db.php);
?>

It is the same as having the contents:

<?php
$conn = pg_connect();
?>


When you execute a query with pg_exec you are using the current connection,
not establishing a new one.

There is no reason to use the global keyword to access the value of $conn,
unless you are trying to access $conn inside of the function.


I believe you are looking for the persistant connection function, in that
you don't have to open a new connection for every time the script is run.
However, you must still make a call to pg_pconnect before you attempt to
query your database.


Anyway, using include while not open a new connection for each query. But it
will open a new connection for each time the page is visited.


--
Plutarck
Should be working on something...
...but forgot what it was.



""Picard, Cyril"" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
include will help me to organize my scripts, but it will effectively
establish the connection each time I perform the query.
I would like to establish the connection one time, and then to be able to
perform many queries using this connection.
I've been told that i could declare $conn as global in both script :
-- connect.php:
   global $conn;
   $conn = pg_connect ...

-- query.php:
   global $conn;
   $res = pg_exec( $conn, ...

What do you think about this way ?

> -----Message d'origine-----
> De: Johannes Janson [SMTP:[EMAIL PROTECTED]]
> Date: mercredi 18 avril 2001 12:42
> À: [EMAIL PROTECTED]
> Objet: Re: [PHP] Connection to postgresql DB used by 2 scripts ?
>
> Hi,
>
> put: include("connect.php"); at the beginning of query.php.
>
> Johannes
>
> ""Picard, Cyril"" <[EMAIL PROTECTED]> schrieb im Newsbeitrag
> [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> > I would like to query a postgresql db with the php language.
> > Today I wrote a script (connectandquery.php) performing the following :
> > - connect to the DB : $conn = pg_Connect("dbname = foo");
> > - execute the query : $res = pg_Exec($conn,"SELECT * from BAR");
> >
> >
> > But I would like to write this in two scripts :
> > - connect.php : $conn = pg_Connect("dbname = foo");
> > - query.php : $res = pg_Exec($conn,"SELECT * from BAR");
> >
> > but I don't know how to get the $conn variable (defined in connect.php)
> in
> > the script query.php.
> >
> > Any idea is welcome !
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> > To contact the list administrators, e-mail: [EMAIL PROTECTED]
> >
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to