"the postmaster running (with -i) at 'localhost' and accepting connections on TCP/IP port '5432'?"
is it?
if it's not running on the default port (5432), you can specify it in your pg_connect function:
pg_connect("host=localhost db=mydb port=9999")
if you're sure everything is correct with your settings, try your real server name instead of localhost (e.g.: myserver.mydomain.com).
another try (under linux): has the www (web server) user got the permissions for accessing this pg database? try logging in as www (if it's called www on your system. could be wwwrun or something else, too. ask your admin) and accessing postgres, eg: psql mydb
hope this helps!