Connecting PostgreSQL db using Pear
Connecting PostgreSQL db using Pear
От:
Devrim GUNDUZ <devrim@oper.metu.edu.tr>
Дата:
Hi all, I've been trying to connect to a local PostgreSQL server using Pear, but I could not succeed: Here is the connect string: $dsn = "pgsql://$username:$password@tcp($hostname:$port)/$dbname"; And all the variables seems to be ok when I print $dsn. However, I get the following error: "DB Error: connect failed" What should I do to correct this? Best regards. -- Devrim GUNDUZ devrim@oper.metu.edu.tr Tel : (312) 295 9318 devrim.gunduz@linux.org.tr Faks : (312) 295 9494 Web : http://devrim.oper.metu.edu.tr ------------------------------------
Re: Connecting PostgreSQL db using Pear
От:
Andrew McMillan <andrew@catalyst.net.nz>
Дата:
On Tue, 2002-10-01 at 04:59, Devrim GUNDUZ wrote:
> Hi all,
>
> I've been trying to connect to a local PostgreSQL server using Pear, but I
> could not succeed:
>
> Here is the connect string:
>
> $dsn = "pgsql://$username:$password@tcp($hostname:$port)/$dbname";
>
> And all the variables seems to be ok when I print $dsn.
>
> However, I get the following error:
>
> "DB Error: connect failed"
>
> What should I do to correct this?
Can you confirm that the postmaster is started with support for TCP
connections? It is possible that in other instances you are connecting
via unix sockets.
I haven't used PEAR myself, but that seems like one possible problem
with the sort of connect string above.
More information might mean others could provide more help.
Cheers,
Andrew.
--
---------------------------------------------------------------------
Andrew @ Catalyst .Net.NZ Ltd, PO Box 11-053, Manners St, Wellington
WEB: http://catalyst.net.nz/ PHYS: Level 2, 150-154 Willis St
DDI: +64(4)916-7201 MOB: +64(21)635-694 OFFICE: +64(4)499-2267
Survey for free with http://survey.net.nz/
---------------------------------------------------------------------
Re: Connecting PostgreSQL db using Pear
От:
Devrim GUNDUZ <devrim@oper.metu.edu.tr>
Дата:
Hi, (sorry for the late response...) On 2 Oct 2002, Andrew McMillan wrote: > Can you confirm that the postmaster is started with support for TCP > connections? It is possible that in other instances you are connecting > via unix sockets. Good point. Tried this connection parameters in two different servers. One of them uses Unix domain sockets, the other has a tcp_ip port open... Anyway, does someone has an example of PostgreSQL + Pear? Best regards. -- Devrim GUNDUZ devrim@oper.metu.edu.tr Tel : (312) 295 9318 devrim.gunduz@linux.org.tr Faks : (312) 295 9494 Web : http://devrim.oper.metu.edu.tr ------------------------------------
Re: Connecting PostgreSQL db using Pear
От:
Vince Vielhaber <vev@michvhf.com>
Дата:
On Fri, 4 Oct 2002, Devrim GUNDUZ wrote:
>
> Hi,
>
> (sorry for the late response...)
>
> On 2 Oct 2002, Andrew McMillan wrote:
>
> > Can you confirm that the postmaster is started with support for TCP
> > connections? It is possible that in other instances you are connecting
> > via unix sockets.
>
> Good point. Tried this connection parameters in two different servers.
> One of them uses Unix domain sockets, the other has a tcp_ip port open...
>
> Anyway, does someone has an example of PostgreSQL + Pear?
Strangely enough, yes. I just did it this week.
// include pear's db stuff
require_once 'DB.php';
// set up your data source
$dsn = "pgsql://vev@localhost/mydatabase";
// connect to your data source
$db = DB::connect($dsn, false);
if (DB::isError($db)) {
die ($db->getMessage());
}
// make your query
$query = "select a from foo";
$res = $db->query($query);
if (DB::isError($res)) {
echo("$query\n");
die ($res->getMessage());
}
// display your results
while ($row = $res->fetchRow())
echo("$row[0]
\n");
// disconnect and return
$db->disconnect();
return;
Quite simple actually. I was surprised. The docs make it look
a whole lot harder than it is.
Vince.
--
==========================================================================
Vince Vielhaber -- KA8CSH email: vev@michvhf.com http://www.pop4.net
56K Nationwide Dialup from $16.00/mo at Pop4 Networking
http://www.camping-usa.com http://www.cloudninegifts.com
http://www.meanstreamradio.com http://www.unknown-artists.com
==========================================================================
Re: Connecting PostgreSQL db using Pear
От:
Devrim GUNDUZ <devrim@oper.metu.edu.tr>
Дата:
Hi Vince, On Fri, 4 Oct 2002, Vince Vielhaber wrote: > Strangely enough, yes. I just did it this week. > No, I still could not succeed... Here is my pg_hba.conf file: local all password passwdf host all 127.0.0.1 255.255.255.255 password passwdf here is the part of postgresql.conf file: tcpip_socket = false #port = 5432 So, what should be the $dsn variable?? Best regards, -- Devrim GUNDUZ devrim@oper.metu.edu.tr Tel : (312) 295 9318 devrim.gunduz@linux.org.tr Faks : (312) 295 9494 Web : http://devrim.oper.metu.edu.tr ------------------------------------
Re: Connecting PostgreSQL db using Pear
От:
Vince Vielhaber <vev@michvhf.com>
Дата:
On Fri, 4 Oct 2002, Devrim GUNDUZ wrote:
>
> Hi Vince,
>
> On Fri, 4 Oct 2002, Vince Vielhaber wrote:
>
> > Strangely enough, yes. I just did it this week.
> >
>
> No, I still could not succeed...
>
> Here is my pg_hba.conf file:
>
> local all password passwdf
> host all 127.0.0.1 255.255.255.255 password passwdf
>
> here is the part of postgresql.conf file:
>
> tcpip_socket = false
> #port = 5432
>
>
> So, what should be the $dsn variable??
Ok, my example assumed you were set up for trust not password.
pgsql://username:password@unix+localhost/database_name
That *should* do it.
Vince.
--
==========================================================================
Vince Vielhaber -- KA8CSH email: vev@michvhf.com http://www.pop4.net
56K Nationwide Dialup from $16.00/mo at Pop4 Networking
http://www.camping-usa.com http://www.cloudninegifts.com
http://www.meanstreamradio.com http://www.unknown-artists.com
==========================================================================
Re: Connecting PostgreSQL db using Pear
От:
Devrim GUNDUZ <devrim@oper.metu.edu.tr>
Дата:
Hi Vince, On Fri, 4 Oct 2002, Vince Vielhaber wrote: > Ok, my example assumed you were set up for trust not password. > > pgsql://username:password@unix+localhost/database_name > > That *should* do it. Yes, it did it! Thanks a lot Vince, you saved a lot of time... Let me now continue coding my project :) Best wishes. -- Devrim GUNDUZ devrim@oper.metu.edu.tr Tel : (312) 295 9318 devrim.gunduz@linux.org.tr Faks : (312) 295 9494 Web : http://devrim.oper.metu.edu.tr ------------------------------------