Reputation: 171
I'm trying to connect to postgres databse on heroku but it doesn't work for me.
This is the code in index.php
<?php
$host = "my host";
$dbname = "my database name";
$user = "my username";
$password = "my password";
$port = "5432";
$dsn = "pgsql:host=$host;dbname=$dbname;user=$user;port=$port;password=$password";
$db = new PDO($dsn);
if($db){
echo "Connected <br />".$db;
}else {
echo "Not connected";
}
?>
But nothing appear on the screen it should print not connected if the credentials are wrong.
Help Please
Thanks all
Upvotes: 1
Views: 3384
Reputation:
Try next code, it works with me.
<?php
$con = "dbname=fgsfg10pdq host=ghfghfh4654.amazonaws.com port=5432 user=gafasduyiu password=435346af8493196 sslmode=require";
if (!$con)
{
echo "Database connection failed.";
}
else
{
echo "Database connection success.";
}
?>
Upvotes: 0