This is weird, it works for me, I use Oracle though. The real application uses ADODB but it should work with the PHP native resources.
I do this: 1. Define a singleton function, for example: getDBConnection() function &getDBConnection() { $db =& GLOBALS['APP_DB_CONNECTION']; if (!is_object($db)) { // Here we make the connection $db =& WHAT_EVER_CONNECTION_FUNCTION_YOU_WANT(); // At this point $db is a valid connection object GLOBALS['APP_DB_CONNECTION'] =& $db; } return $db } 2. From every function that connects to the database you just call the singleton: function &getActiveCustomers() { $db =& getDBConnection(); $sql = "SELECT ....."; // Here you execute the sql like you normally would return $rs; // This is the resultset } Note that in step 1 you can use the resource variable returned by native PHP functions, in my case I use ADODB so I store the object which isn't that different because inside that object resides the PHP resource. So you can change the line 'if (!is_object($db))' for 'if(!is_resource($db))'. If you look the singleton carefully you'll see that the connection process is executed just the first time. For example, if a user requests executes 10 queries to the database, the connection will be actually made in the first call to the singleton. The successive calls will return the connection stored in the global scope. I can tell for sure that this approach works very well. If it doesn't for you, there might be a more fundamental problem in your configuration or in your code. Regards, -William El lun, 05-04-2004 a las 17:18, Monty escribió: > > A define is pretty much for strings only, not objects or resources. Try > > using $GLOBALS['_CONNECT_DB'] instead. > > I tried this, but, same results. If I store the Resource ID from a > mysql_pconnect() in $GLOBALS['_CONNECT_DB'] and then call... > > mysql_query($query, $GLOBALS['_CONNECT_DB']); > > PHP gives me the following error: > > 4 is not a valid MySQL-Link resource > > When I look into this var, here's what I see: > > Resource id #4 > > This is the same that was stored in the constant var, so, it appears that > whether it's a Global or Constant isn't making a difference. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php