Re: Connection to postgresql DB used by 2 scripts ?

From: Date: Wed, 18 Apr 2001 13:51:40 +0000
Subject: Re: Connection to postgresql DB used by 2 scripts ?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-49215@lists.php.net to get a copy of this message
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"" <cyril.picard@eads-dsn.com> wrote in message news:B5CDCF382265D311BF33009027A8FE9401E6F3C2@pmrmsg.edsn.com... 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:johannes.janson@gmx.de] > Date: mercredi 18 avril 2001 12:42 > À: php-general@lists.php.net > 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"" <cyril.picard@eads-dsn.com> schrieb im Newsbeitrag > news:B5CDCF382265D311BF33009027A8FE9401E6F3BD@pmrmsg.edsn.com...s=—Iyi^©mpñ ¶ > Å$ > > 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: php-general-unsubscribe@lists.php.net > > For additional commands, e-mail: php-general-help@lists.php.net > > To contact the list administrators, e-mail: php-list-admin@lists.php.net > > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#49215) next »