X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id BF7BF54069 for ; Sat, 30 Apr 2005 05:36:44 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 01828-03 for ; Sat, 30 Apr 2005 08:36:43 +0000 (GMT) Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.206]) by svr1.postgresql.org (Postfix) with ESMTP id 36A5B5406D for ; Sat, 30 Apr 2005 05:36:42 -0300 (ADT) Received: by wproxy.gmail.com with SMTP id 68so1185042wri for ; Sat, 30 Apr 2005 01:36:44 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=LHu88Y1Q/Z6W0J3wQFLyvKFO2kdzoQujoh9pndrkqilx1rq3iyJ/FzQELFcltmbNsJ3Cqc9uoXArAkN1CgeVNVAxx4ZG5uCz05Nh/PJntucxoOwJX5d/slU2usy+mAGgZEtsWKzjtw57BictjKsZHm5dKz7CdZ32z5/dqDFk07k= Received: by 10.54.18.34 with SMTP id 34mr840935wrr; Sat, 30 Apr 2005 01:36:44 -0700 (PDT) Received: by 10.54.30.31 with HTTP; Sat, 30 Apr 2005 01:36:44 -0700 (PDT) Message-ID: <7104a73705043001361a666de0@mail.gmail.com> Date: Sat, 30 Apr 2005 11:36:44 +0300 From: Volkan YAZICI Reply-To: Volkan YAZICI To: pgsql-sql@postgresql.org Subject: Re: PHP postgres connections In-Reply-To: <20050429163134.69632.qmail@web25605.mail.ukl.yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <20050429163134.69632.qmail@web25605.mail.ukl.yahoo.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.298 tagged_above=0 required=5 tests=AWL, DNS_FROM_RFC_ABUSE, RCVD_BY_IP X-Spam-Level: X-Archive-Number: 200504/417 X-Sequence-Number: 21310 Hi, On 4/29/05, Mauro Bertoli 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 connectio= n 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 =3D "..."; $this->connParam2 =3D "..."; } function connect($connParam) { /* Pay attention to SQL_CONNECT_FORCE_NEW parameter. */ return pg_connect($connParam, SQL_CONNECT_FORCE_NEW); } /* ... */ } /* Creating DB Wrapper */ $dbw =3D new dbw(); /* * If we're not happy with the current connParam1 value: * $dbw->connParam1 =3D "..."; */ $dbConn1 =3D $dbw->connect($dbw->connParam1); $dbConn2 =3D $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 question= s.