pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Connecting PostgreSQL db using Pear
7+ messages / 3 participants
[nested] [flat]

* Connecting PostgreSQL db using Pear
@ 2002-09-30 16:59  Devrim GUNDUZ <devrim@oper.metu.edu.tr>
  0 siblings, 1 reply; 7+ messages in thread

From: Devrim GUNDUZ @ 2002-09-30 16:59 UTC (permalink / raw)
  To: pgsql-php


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
		------------------------------------






^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Connecting PostgreSQL db using Pear
@ 2002-10-02 01:50  Andrew McMillan <andrew@catalyst.net.nz>
  parent: Devrim GUNDUZ <devrim@oper.metu.edu.tr>
  0 siblings, 1 reply; 7+ messages in thread

From: Andrew McMillan @ 2002-10-02 01:50 UTC (permalink / raw)
  To: Devrim GUNDUZ <devrim@oper.metu.edu.tr>; +Cc: pgsql-php

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/ 
---------------------------------------------------------------------




^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Connecting PostgreSQL db using Pear
@ 2002-10-04 17:27  Devrim GUNDUZ <devrim@oper.metu.edu.tr>
  parent: Andrew McMillan <andrew@catalyst.net.nz>
  0 siblings, 1 reply; 7+ messages in thread

From: Devrim GUNDUZ @ 2002-10-04 17:27 UTC (permalink / raw)
  To: Andrew McMillan <andrew@catalyst.net.nz>; +Cc: pgsql-php


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
		------------------------------------








^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Connecting PostgreSQL db using Pear
@ 2002-10-04 17:39  Vince Vielhaber <vev@michvhf.com>
  parent: Devrim GUNDUZ <devrim@oper.metu.edu.tr>
  0 siblings, 1 reply; 7+ messages in thread

From: Vince Vielhaber @ 2002-10-04 17:39 UTC (permalink / raw)
  To: Devrim GUNDUZ <devrim@oper.metu.edu.tr>; +Cc: Andrew McMillan <andrew@catalyst.net.nz>; pgsql-php

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<P>\n");
		die ($res->getMessage());
	}


// display your results
	while ($row = $res->fetchRow())
		echo("$row[0]<br>\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
==========================================================================






^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Connecting PostgreSQL db using Pear
@ 2002-10-04 18:16  Devrim GUNDUZ <devrim@oper.metu.edu.tr>
  parent: Vince Vielhaber <vev@michvhf.com>
  0 siblings, 1 reply; 7+ messages in thread

From: Devrim GUNDUZ @ 2002-10-04 18:16 UTC (permalink / raw)
  To: Vince Vielhaber <vev@michvhf.com>; +Cc: pgsql-php


Hi Vince,

On Fri, 4 Oct 2002, Vince Vielhaber wrote:

> Strangely enough, yes.  I just did it this week.
> <snip>

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
		------------------------------------




^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Connecting PostgreSQL db using Pear
@ 2002-10-04 18:46  Vince Vielhaber <vev@michvhf.com>
  parent: Devrim GUNDUZ <devrim@oper.metu.edu.tr>
  0 siblings, 1 reply; 7+ messages in thread

From: Vince Vielhaber @ 2002-10-04 18:46 UTC (permalink / raw)
  To: Devrim GUNDUZ <devrim@oper.metu.edu.tr>; +Cc: pgsql-php

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.
> > <snip>
>
> 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
==========================================================================






^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Connecting PostgreSQL db using Pear
@ 2002-10-04 18:55  Devrim GUNDUZ <devrim@oper.metu.edu.tr>
  parent: Vince Vielhaber <vev@michvhf.com>
  0 siblings, 0 replies; 7+ messages in thread

From: Devrim GUNDUZ @ 2002-10-04 18:55 UTC (permalink / raw)
  To: Vince Vielhaber <vev@michvhf.com>; +Cc: pgsql-php


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
		------------------------------------




^ permalink  raw  reply  [nested|flat] 7+ messages in thread


end of thread, other threads:[~2002-10-04 18:55 UTC | newest]

Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-09-30 16:59 Connecting PostgreSQL db using Pear Devrim GUNDUZ <devrim@oper.metu.edu.tr>
2002-10-02 01:50 ` Andrew McMillan <andrew@catalyst.net.nz>
2002-10-04 17:27   ` Devrim GUNDUZ <devrim@oper.metu.edu.tr>
2002-10-04 17:39     ` Vince Vielhaber <vev@michvhf.com>
2002-10-04 18:16       ` Devrim GUNDUZ <devrim@oper.metu.edu.tr>
2002-10-04 18:46         ` Vince Vielhaber <vev@michvhf.com>
2002-10-04 18:55           ` Devrim GUNDUZ <devrim@oper.metu.edu.tr>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox