SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    I am obstructing justice. bronze trophy fatnewt's Avatar
    Join Date
    Jul 2002
    Location
    Ottawa, Canada
    Posts
    1,766
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Can't connect to PostgreSQL from PHP.

    I'm having some problems connecting to PostgreSQL from PHP.

    Here's the code I'm using to connect:

    PHP Code:
     <?php
     
     $pgHostname 
    "localhost";
     
    $pgPort "5432";
     
    $pgDatabase "mydb";
     
    $pgUsername "someone";
     
    $pgPassword "foo";
     
     
    $connectstring "host=$pgHostname port=$pgPort dbname=$pgDatabase user=$pgUsername password=$pgPassword";
     
     
    $pgcnx pg_connect($connectstring);
     
     
    $stat pg_connection_status($pgcnx);
     
     if (
    $stat === 0) {
        echo 
    'Connection status ok';
     } else {
        echo 
    'Connection status bad';
     }
     
     
    ?>
    (I changed the username/dbname for security reasons, obviously).

    This script outputs "Connection status bad".

    The same settings work using pgAdmin... but I can't connect from PHP itself. PHP version is 4.3.9.

    Any suggestions?
    Colin Temple [twitter: @cailean]
    Web Analyst at Napkyn


  2. #2
    I am obstructing justice. bronze trophy fatnewt's Avatar
    Join Date
    Jul 2002
    Location
    Ottawa, Canada
    Posts
    1,766
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Problem resolved: turns out the administrator for the server hadn't enabled my account to actually connect. Sorry to bother.
    Colin Temple [twitter: @cailean]
    Web Analyst at Napkyn



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •