Jump to content

not connecting to database


jb489

Recommended Posts

Hi all,

 

i have just made some sortware and am testing it live.  I have a connection string like so which is in a config file:

 

host=test.com user=testu password=testp dbname=testdb

 

When i try to connect using this code:

 

public function getDataSet($ConnectionString, $Query)

{

$DataArr = array();

 

$conn = pg_connect($ConnectionString);

try{

if (!$conn) {

throw new Exception("Error Connecting to database. Please check configuration file.");

} else {

$result = pg_query($Query);

if (!$result)

{

throw new Exception("No user matches the search.");

}

else

{

$numrows = pg_numrows($result);

 

for ($i=0; $i < $numrows ; $i++)

{

$DataArr[] = pg_fetch_assoc($result, $i);

}

pg_close($conn);

return $DataArr;

}

}

}

catch(Exception $e)

{

pg_close($conn);

throw new Exception($e->getMessage());

}

}

 

I get back this error:

 

pg_connect(): Unable to connect to PostgreSQL server: FATAL:  no pg_hba.conf entry for host "xxx.xxx.xxx.xxx", user "testu", database "testdb", SSL off

 

I cannot change the pg_hba.conf file as this means restarting their database server which is out of the question.

 

any ideas ?

Link to comment
https://forums.phpfreaks.com/topic/169110-not-connecting-to-database/
Share on other sites

i have changed it now to:

 

host=test.com user=user password=password dbname=db sslmode=require port=5432

 

and get this error:

 

pg_connect(): Unable to connect to PostgreSQL server: sslmode value "require" invalid when SSL support is not compiled in

 

but the postgres database has it inbuilt for sure as i connect to it with pgadmin3 and the ssl option as required and it works

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.