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.
Make sure you have pgsql
php extension installed.
And turn on error displaying in php.ini
display_errors = On display_startup_errors = On
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;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.