|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2016-07-05 02:19 UTC] floriparob at gmail dot com
Description:
------------
The documentation for pg_connect says that it recognises the "service" parameter as a connect string.
In the pg_service.conf file you can have entries for several databases, each with their own distinct IP addresses, passwords, etc. So, in your PHP code you'd expect to be able to do something like this wrapped up in a try catch block:-
$connect_string = "service=staging";
$pg_handle = pg_connect($connect_string);
to access the "staging" data base.
With psql you have to do this:-
PGSERVICE=staging;export PGSERVICE
psql
is run without any parameters. It opens the pg_service.conf file and finds the entry defined as "staging" and from that obtains all the necessary configuration parameters in order to open a connection to that database.
I tried this:-
putenv("PGSERVICE=staging");
$connect_string = "service=staging";
$pg_handle = pg_connect($connect_string);
but still no luck.
So, if this is not a bug could somebody please enlighten me about the correct way to connect using pg_service.conf.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 04:00:01 2025 UTC |
After reading your reply it functions as follows:- putenv("PGSERVICEFILE=/path/to/your/service/file/pg_service.conf"); $conn_string = "service=testdb"; try { $pgconn_handle = pg_connect($conn_string); . . . etc. You need to set PGSERVICEFILE to the complete path and file name. The file has to be readable by apache. I'll add some comments about this to the pg_connect documentation. This report may be closed.