[pmwiki-devel] More database standards

marc gmane at auxbuss.com
Wed Dec 13 13:11:13 CST 2006


I know that most folk aren't using a database, and probably very few are 
using more than one, but I'd like to pin down how we communicate the 
active connection name to recipes even for a single db.

A connection is usually defined in (farm)config.php by:

  $Databases['connection_name'] = array(...

where connection_name is arbitrary. This means that when a recipe needs 
it - to perform some db action - the connection name must be somehow 
passed to the recipe. One could pass it around in parameters, but that 
is horribly messy. Worse, when dealing with objects, it's not really 
viable at all. 

To complicate matters, where there is more than one database, you could 
be passing around multiple connection names. In addition, how is a 
recipe writer to cater for the situation where one table comes from one 
db and a second from another? And perhaps a third. Or a fourth. 

Is there a proposed solution for this?

(Currently, I am creating arrays for each table. Something like:

  $dbProductsTable = array(
    'database'      => $liveDb,
    'productstable' => 'products'
  );

where $liveDb is set via something like:

  $test = true;
  if ($test) $liveDb = 'testdb'; else $liveDb = 'localdb';

although multiple variables can be used.

The recipe or object can then interrogate this with:

  global $dbProductsTable;
)

-- 
Best,
Marc




More information about the pmwiki-devel mailing list