I am trying to create a simple php application on heroku with postgresql back end. I have created a connection to postgresql server with the provided credentials from heroku:-
<?php
class DB_Connect
{
private $db;
public function connect()
{
$host = "";
$port = "port=5432";
$dbname = "";
$credentials = "user= password=";
$db = pg_connect( " $url $host $port $dbname $credentials" );
if(!$db){
echo "Error : Unable to open database\n";
} else {
echo "Opened database successfully\n";
}
}
}
$db1 = new DB_Connect();
$conn = $db1->connect();
$query = "insert into public.user_test(name,email) values('val','[email protected]')";
$result = pg_query($conn,$query);
echo $result;
?>
When i deploy the app on heroku, I get a Opened Database successfully message but nothing gets inserted into the table when I check the table using pgadmin.
I tried it with and without the schema name "public", but that didn't help either.
When I run the app locally by providing the local postgresql credentials, the table gets populated.
$dbfrom$db = pg_connect..is not the same as the one fromprivate $db.