are you running the "old" pgsql connection command. It looks like
pg_connect("", "", "", "", "databasename");
ie, it takes 5 args instead of one. I only mention this because it appears you're running php3 and I'm not sure when the change was made. Note that the old call still works with newer versions of php