#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Location
    Los Angeles, CA
    Posts
    85
    Rep Power
    13

    Can't get Postgres to connect with pg_connect()


    hey guys,
    I installed postgresql on my windows box and I'm trying to get it to connect with PHP.

    here is where I'm at:

    its installed properly - I created a db and tables using pgsql command line scripts, that works fine.

    I un commented out the semi-colon ; in the php.ini file for the pgsql.dll extension

    I restarted apache but I keep getting the following msg:

    Warning: pg_connect() [function.pg-connect]: Unable to connect to PostgreSQL server: could not connect to server: No connection could be made because the target machine actively refused it. (0x0000274D) Is the server running on host webdev and accepting TCP/IP connections on port 5432? . in c:\www\pgsql\test.php on line 2



    PHP Code:
    $db_handle pg_connect("host=webdev dbname=test user=jim password=test") or die("Couldn't Connect: ".pg_last_error()); 
    anyone have any thoughts on what it could be? I haven't been able to find anything on it
    ~jim~
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    373
    Rep Power
    12
    postmaster has to be running with TCP/IP socket connections enabled. You can check what its startup options were with pg_ctl status I think, or you can un-comment that option in the postgresql.conf file now I don't know if this is all the same stuff in windows but I would imagine. I'd actually try to convince you to make your machine a dual boot with some distro of Linux so you can use postgres and related utilities more easily, but I suppose it is a matter of personal preference.

    Also, at least with linux/unix you have to have configured php to --enable-pgsql or --with-pgsql to be allowed to use those functions. That doesn't seem to be the problem since the function at least returned with that error state.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Location
    Los Angeles, CA
    Posts
    85
    Rep Power
    13
    turned out to be a problem with the pg_hba.conf file

    changed the host line and now I can connect just dandily

IMN logo majestic logo threadwatch logo seochat tools logo