[clug] PHP gurus? How can I find an "anonymous" mysql resource?

Tony and Robyn Lewis beakysnugger at yahoo.co.uk
Sat Jun 17 14:31:06 GMT 2006

Pardon being OT, but I'm hoping someone on list can help with a PHP problem.

We've got lots of hand-crafted PHP pages, and there is typically one DB 
connection per page.  Now we want to insert ("include") a common set of 
pages that, amongst other things, makes a different DB connection.

Unfortunately, once our included code finishes, the existing MySQL 
connection is a goner, because it was never saved (as in, at 
mysql_connect() time), and up to now it worked, because mysql_query() 
will use the resource of the last mysql_connect().

Is there a way I can essentially put the current MySQL resource (the 
variable associated with the connection) onto a stack (or just save it 
in a var), let the inserted code do its bit, and then restore / pop the 
old resource to be the current resource?

Or is there a better way, other than rewriting the existing code to 
properly save and use the resource?

Please, no sermons - this is inherited code, and I dislike PHP enough 
already.  I especially disrelish the idea of hand-editing scores of PHP 
pages looking for mysql calls.



More information about the linux mailing list