Connecting PostgreSQL db using Pear

Connecting PostgreSQL db using Pear

am 30.09.2002 18:59:42 von Devrim GUNDUZ

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




---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

Re: Connecting PostgreSQL db using Pear

am 02.10.2002 03:50:16 von Andrew McMillan

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


---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo@postgresql.org)

Re: Connecting PostgreSQL db using Pear

am 04.10.2002 19:27:04 von Devrim GUNDUZ

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






---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/users-lounge/docs/faq.html

Re: Connecting PostgreSQL db using Pear

am 04.10.2002 19:39:47 von Vince Vielhaber

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




---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/users-lounge/docs/faq.html

Re: Connecting PostgreSQL db using Pear

am 04.10.2002 20:16:52 von Devrim GUNDUZ

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


---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

Re: Connecting PostgreSQL db using Pear

am 04.10.2002 20:46:22 von Vince Vielhaber

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




---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Re: Connecting PostgreSQL db using Pear

am 04.10.2002 20:55:47 von Devrim GUNDUZ

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


---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster