Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2010

    Unanswered: POSTGRE connection in PHP

    Hi guys... Kindly Help me how to connect my php program to postgre...
    i tried the code below but it returned the same code in the browser. Please thank you in advance:

    $connect = "dbname=dbSample user=postgres host=localhost:82 port=5433";

    $fname = $_POST[fname];
    $lname = $_POST[lname];
    $mi = $_POST[mi];
    $pass = $_POST[paswrd];
    $conpass =$_POST[retype];
    $recov = $_POST[recovery];

    if($fname ==false || $lname == false || $mi ==false || $ead ==false || $pass == false || $conpass == false || $recov ==false){
    echo "Please fill in all the required fields";
    if ($pass!=$conpass){
    echo "Passwords do not match";
    else {
    $connect = "dbname=dbSample user=postgres host=localhost:82 port=5433";
    $sql ="INSERT INTO sample (fname,lname,mi,ead,pass,conpass,recov) VALUES ($fname,$lname,$mi,$ead,$pass,$conpass,$recov)";
    $result = pg_query($sql);
    echo "thank you for your registration.";


  2. #2
    Join Date
    May 2008
    Quote Originally Posted by ashin View Post
    $connect = "dbname=dbSample user=postgres host=localhost:82 port=5433";
    Your problem likely lies in here.

    You only need to specify those settings that differ from the defaults. So unless you've changed your server's default configuration, usually this means you only need to specify a dbname and a user.

    Localhost is the default host. But if you want to explicitly specify it, then it should just be "localhost"; no number. Similarly, PostgreSQL's default port is 5432, unless you've changed it.

    I'm also guessing you don't have privileges to connect as the postgres user. Although you haven't specified what system you're working on (Windows? Linux?), or what the actual error message is you're getting.

  3. #3
    Join Date
    Aug 2009
    Olympia, WA
    You need to remove the ":82" in localhost:82

    And it is Postgres or PostgreSQL not Postgre.

Posting Permissions

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