pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Can't connect to 7.4 DB
4+ messages / 3 participants
[nested] [flat]

* Can't connect to 7.4 DB
@ 2004-02-12 13:36 Michael Hanna <taojones@sympatico.ca>
  2004-02-12 15:30 ` Re: Can't connect to 7.4 DB scott.marlowe <scott.marlowe@ihs.com>
  2004-02-12 15:31 ` Re: Can't connect to 7.4 DB Joshua Drake <jd@commandprompt.com>
  0 siblings, 2 replies; 4+ messages in thread

From: Michael Hanna @ 2004-02-12 13:36 UTC (permalink / raw)
  To: pgsql-php

Hi this php code:


	
	// add to DB
	
	// database access parameters
	$host = "localhost";
	$user = "postgres";
	$pass = "postgres";
	$db = "cosc3p94";
	
	// open a connection to the database server
	$connection = pg_connect("host=$host dbname=$db user=$user 
password=$pass");
	
	if (!$connection)
	{
			die("Could not open connection to database server");
	}
	

	...

results in:

Could not open connection to database server

and I'm not sure why. The web browser, web server, and database are on 
the same machine..

I checked the pg_hba.conf and it says this:

# TYPE  DATABASE    USER        IP-ADDRESS        IP-MASK           
METHOD

local   all         all                                             
trust
# IPv4-style local connections:
host    all         all         127.0.0.1         255.255.255.255   
trust
# IPv6-style local connections:
host    all         all         ::1               
ffff:ffff:ffff:ffff:ffff:ffff:ff$


which is untouched from the default settings...

Michael




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

* Re: Can't connect to 7.4 DB
  2004-02-12 13:36 Can't connect to 7.4 DB Michael Hanna <taojones@sympatico.ca>
@ 2004-02-12 15:30 ` scott.marlowe <scott.marlowe@ihs.com>
  2004-02-12 17:50   ` Re: Can't connect to 7.4 DB Michael Hanna <taojones@sympatico.ca>
  1 sibling, 1 reply; 4+ messages in thread

From: scott.marlowe @ 2004-02-12 15:30 UTC (permalink / raw)
  To: Michael Hanna <taojones@sympatico.ca>; +Cc: pgsql-php

OK, here's a little trick you may not be aware of.

pg_connect("dbname=mydb user=stan");

will open a local unix domain socket.

pg_connect("host=127.0.0.1 dbname=mydb user=stan");

will open a local TCP/IP connection on the loopback interface.

In order for this to work, your postgresql.conf must have this line 
changed:
#tcpip_socket = false
to
tcpip_socket = true

and your pg_hba.conf needs a line like this:

host    all         all         127.0.0.1         255.0.0.0   trust

So it's likely the "secure by default" mentality of postgresql that's 
biting you here.




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

* Re: Can't connect to 7.4 DB
  2004-02-12 13:36 Can't connect to 7.4 DB Michael Hanna <taojones@sympatico.ca>
  2004-02-12 15:30 ` Re: Can't connect to 7.4 DB scott.marlowe <scott.marlowe@ihs.com>
@ 2004-02-12 17:50   ` Michael Hanna <taojones@sympatico.ca>
  0 siblings, 0 replies; 4+ messages in thread

From: Michael Hanna @ 2004-02-12 17:50 UTC (permalink / raw)
  To: scott.marlowe <scott.marlowe@ihs.com>; +Cc: pgsql-php

yes, this was the problem, thanks...

On 12-Feb-04, at 10:30 AM, scott.marlowe wrote:
>
> In order for this to work, your postgresql.conf must have this line
> changed:
> #tcpip_socket = false
> to
> tcpip_socket = true




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

* Re: Can't connect to 7.4 DB
  2004-02-12 13:36 Can't connect to 7.4 DB Michael Hanna <taojones@sympatico.ca>
@ 2004-02-12 15:31 ` Joshua Drake <jd@commandprompt.com>
  1 sibling, 0 replies; 4+ messages in thread

From: Joshua Drake @ 2004-02-12 15:31 UTC (permalink / raw)
  To: Michael Hanna <taojones@sympatico.ca>; +Cc: pgsql-php

Hello,

What does the PostgreSQL log say? Is it even getting to the server? What 
abour the apache error log? Does it reflect an error?

Sincerely,

Joshua D. Drake


Michael Hanna wrote:
> Hi this php code:
> 
> 
>     
>     // add to DB
>     
>     // database access parameters
>     $host = "localhost";
>     $user = "postgres";
>     $pass = "postgres";
>     $db = "cosc3p94";
>     
>     // open a connection to the database server
>     $connection = pg_connect("host=$host dbname=$db user=$user 
> password=$pass");
>     
>     if (!$connection)
>     {
>             die("Could not open connection to database server");
>     }
>     
> 
>     ...
> 
> results in:
> 
> Could not open connection to database server
> 
> and I'm not sure why. The web browser, web server, and database are on 
> the same machine..
> 
> I checked the pg_hba.conf and it says this:
> 
> # TYPE  DATABASE    USER        IP-ADDRESS        IP-MASK           METHOD
> 
> local   all         all                                             trust
> # IPv4-style local connections:
> host    all         all         127.0.0.1         255.255.255.255   trust
> # IPv6-style local connections:
> host    all         all         ::1               
> ffff:ffff:ffff:ffff:ffff:ffff:ff$
> 
> 
> which is untouched from the default settings...
> 
> Michael
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 8: explain analyze is your friend

Attachments:

jd.vcf (text/x-vcard, 345B) download begin:vcard fn:Joshua Drake n:Drake;Joshua org:Command Prompt, Inc. adr:;;P.O. Box 215;Cascade Locks;OR;97014;US email;internet:jd@commandprompt.com title:Consultant tel;work:503-667-4564 tel;fax:503-210-0334 note:Home of Mammoth PostgreSQL, and PostgreSQL Replicator. x-mozilla-html:FALSE url:http://www.commandprompt.com/ version:2.1 end:vcard
^ permalink raw reply [nested|flat] 4+ messages in thread


end of thread, other threads:[~2004-02-12 17:50 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-02-12 13:36 Can't connect to 7.4 DB Michael Hanna <taojones@sympatico.ca>
2004-02-12 15:30 ` scott.marlowe <scott.marlowe@ihs.com>
2004-02-12 17:50   ` Michael Hanna <taojones@sympatico.ca>
2004-02-12 15:31 ` Joshua Drake <jd@commandprompt.com>

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