-1

I am trying to develop a basic page that uses PostgreSQL for the database. The database is already set. Right now I was simply trying to create a connection with it.

<?php
    echo "test 1";
    $dbconn = pg_connect("host='localhost' port='5432' dbname='demorole' user='demorole' password='eta'") or die ("couldnt connect");
    echo "test 2";
?>

demorole is my database and its owner user. eta is a sample of password (but is correct)

My problem is that this page doesn't work at all. It doesn't display any errors. When i use the function pg_connection_status() it doesn't return anything. It only prints "test 1" (the echo commands are for debugging purposes).

I am working on Linux Mint. Both PostgreSQL and Apache are running. The connection info are correct. Any idea what might be wrong? Because, since it doesn't display any errors, I'm stuck.

1
  • Does it work with MySQL? edit: What do the logs say? Commented Jan 22, 2015 at 3:08

2 Answers 2

2

Make sure you have pgsql php extension installed.

And turn on error displaying in php.ini

display_errors = On display_startup_errors = On

Sign up to request clarification or add additional context in comments.

Comments

0

This code worked.

 $host        = "host=127.0.0.1";                         
 $port        = "port=5432";                        
 $dbname      = "dbname=mydb";                         
 $credentials = "user=myrole password=mypsw";

$connection = pg_connect( "$host $port $dbname $credentials"  );
if(!$connection){  echo "Error : Unable to open database\n"; } 
 return $connection;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.