postgresql connection management

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I am running several web sites on one server, each of which connects to a different Postgresql database. I use some include files to load functions and classes. If I put pg_connect at the start of the include file, then sometimes I do not connect to the correct database from functions in a class. If I run echo pg_dbname(); in these functions I see that I am connected to the wrong database. Here are some possible fixes:

1:
$swdbcon = pg_connect("host=localhost dbname=swgap user=postgres"); //at start of file
global $swdbcon; // inside function
$result = pg_query($swdbcon, $query);

2:
if (pg_dbname() != "swgap") { //inside function
          pg_connect("host=localhost dbname=swgap user=postgres");
}

3:
pg_connect("host=localhost dbname=swgap user=postgres"); inside function

I have already written code that does not explicitly set the connection in each function and it worked fine. However, I find the problem occasionally as I change the code. What is the best way to get the proper connection inside functions?

Jim

--
James (Jim) B. White

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux