From: | Volkan YAZICI <volkan(dot)yazici(at)gmail(dot)com> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: PHP postgres connections |
Date: | 2005-04-30 08:36:44 |
Message-ID: | 7104a73705043001361a666de0@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Hi,
On 4/29/05, Mauro Bertoli <bertolima(at)yahoo(dot)it> wrote:
> I need to connect to 2 differents Postgres 8.0.0
> databases located in the same machine using the same
> PHP script with an "db wrapper object" instance
> (pg_Connect)... simply a PHP page with contemporarily
> 2 database connections...
Firstly some extra information from php.net:
{{{
[http://tr.php.net/pg_connect]
resource pg_connect ( string connection_string [, int connect_type] )
...
If a second call is made to pg_connect() with the same connection_string,
no new connection will be established unless you pass
SQL_CONNECT_FORCE_NEW as connect_type, but instead, the connection
resource of the already opened connection will be returned. You can have
multiple connections to the same database if you use different connection
strings.
}}}
Here's a simple db wrapper class for 2 different db connections:
class dbw
{
/* Connection parameter variables. */
var connParam1;
var connParam2;
function dbw()
{
/* Assigning values to conn. params. */
$this->connParam1 = "...";
$this->connParam2 = "...";
}
function connect($connParam)
{
/* Pay attention to SQL_CONNECT_FORCE_NEW parameter. */
return pg_connect($connParam, SQL_CONNECT_FORCE_NEW);
}
/* ... */
}
/* Creating DB Wrapper */
$dbw = new dbw();
/*
* If we're not happy with the current connParam1 value:
* $dbw->connParam1 = "...";
*/
$dbConn1 = $dbw->connect($dbw->connParam1);
$dbConn2 = $dbw->connect($dbw->connParam2);
> Can I use however persistent connections ?
Yep. Just replace pg_connect line in the code with pg_pconnect. But I
(as PHP team) don't recommend using persistent connections. Please
read "Persistent Database Connections" [1] before deciding to use.
[1] http://php.net/manual/en/features.persistent-connections.php
Regards.
P.S. Next time, please try to use pgsql-php listen for PHP related questions.
From | Date | Subject | |
---|---|---|---|
Next Message | Tornroth, Phill | 2005-04-30 15:01:16 | Re: multi-column unique constraints with nullable columns |
Previous Message | Metin Ozisik | 2005-04-30 07:04:36 | Re: Build issues: "-static" builds resulting initdb problems |