[pmwiki-users] most user-friendly method of database configuration
Ben Stallings
Ben at InterdependentWeb.com
Fri Oct 13 12:49:32 CDT 2006
I'm back, looking for more feedback...
Although development on DataQuery has been stalled for the last few days
(no puns on my name, please), Pico and I have been having an interesting
off-list conversation about how to configure the database(s).
In SelectQuery and UpdateForm I did it with constants, and so for
backward-compatibility I did the same in DataQuery. But not only is
this nonstandard in the PmWiki world, Pico has pointed out that it
doesn't allow for multiple simultaneous databases.
What I really want to do, I suppose, is allow people to add as many
DataStore objects (i.e. databases) as they like to their $WikiLibDirs
(i.e. places the wiki looks for pages). (This is assuming, of course,
that I get the recipe finished in the near future!)
The way this would typically be done, I believe, is for the admin to
define a multi-dimensional array in the config.php:
$DQConnections = array(
array(
'type' => 'mysql',
'server' => 'db.example.com',
'name' => 'example_database_name',
'user' => 'example_user',
'passwd' => 'example_password'),
array(
'type' => 'postgres',
'server' => 'postgresql.example.com',
'name' => 'another_example_name',
'user' => 'another_user',
'passwd' => 'another_password'),
array(
'type' => 'access',
'driver' => 'Microsoft Access Driver (*.mdb)',
'path' => 'd:\\northwind.mdb',
'user' => 'Admin',
'passwd' => ''));
include('cookbook/dataquery.php');
and the recipe would then create as many new DataStore objects as there
are sub-arrays, plugging each database's info into the
ADONewConnection() function in turn. The wiki in this example would
look for pages first in wiki.d, then in wikilib.d, then in mysql, then
in postres, and finally in access.
Trouble is, I have a sneaking suspicion that multi-dimensional arrays,
with their fickle commas and their nested parentheses, are intimidating
to people who don't eat PHP for breakfast. I made a mistake myself
while typing it in and only caught it on the third reading, and I *do*
eat PHP for breakfast. PHP Crisp.
So I'm wondering if it might actually be easier to have people add the
DataStore objects to their $WikiLibDirs manually rather than putting the
info into either a set of constants or a variable. Instead of the
above, an aspiring admin might put this into config.php:
include('cookbook/dataquery.php');
$WikiLibDirs[] = new
DataStore('mysql','db.example.com','example_database_name','example_user','example_password');
$WikiLibDirs[] = new
DataStore('postgres','postgresql.example.com','another_database_name','another_user','another_password');
$WikiLibDirs[] = new DataStore('access',"Driver={Microsoft Access
Driver (*.mdb)};Dbq=d:\\northwind.mdb;Uid=Admin;Pwd=;");
(Those with only one database to connect would stop after the first two
lines.)
It seems to me that this second syntax is actually harder to screw up
than the multi-dimensional array. But that could just be me, so I'm
eager for other opinions. Or is there an even simpler syntax I haven't
thought of? --Ben S.
More information about the pmwiki-users
mailing list