Multiple databases in Drupal

Have to say, while MDB2 has the more straightforward way of accessing multiple databases (just create more database objects using MDB2::factory()), drupal’s way of doing things is a long way from horrible.

To initialise:
[ccN lang=”php”]$db_url[‘default’] = ‘mysql://drupal:drupal@localhost/drupal’;
$db_url[‘mydb’] = ‘mysql://user:pwd@localhost/anotherdb’;
$db_url[‘db3’] = ‘mysql://user:pwd@localhost/yetanotherdb’;[/cc]
And then to use:
[ccN lang=”php”]db_set_active(‘mydb’);
db_query(‘SELECT * FROM table_in_anotherdb’);
//Switch back to the default connection when finished.
db_set_active(‘default’);[/cc]

Quite straightfoward looking. Now to see if it actually works! 🙂… Read the rest

Read More

4's dead baby

So PHP 4.4.8 is released, and that’s it for the whole PHP 4 line. No further normal releases are due and PHP 4 is no longer supported. Hopefully this will mean that the takeup figures for 5 get a sudden sharp upwards jolt!

It’s going to be interesting to watch as major apps like Drupal change over from having to provide legacy support for PHP4 and can start to use the better object model in 5 – the question will be, will we see an improvement in the quality of coding as the mainstream toolset improves?… Read the rest

Read More

Reaching the limits of PHP

First off, I rather like PHP. PHP 5 at least, I think PHP 4 was – and remains – a dog’s dinner of a thing at best. But for 90% (at least) of webpages, PHP is a pretty decent solution. Retrieval of data from databases, display of that data, no worries. Minimal learning curve, support for high-level constructs like objects and exceptions, several frameworks available – PHP’s a damn good choice in the vast majority of cases.

Thing is, right now I’m trying to put together a bit of code to act as a proof of concept, and – more fool me – I tried to use PHP to do it, figuring I’d save some time. No such luck. Turns out, trying to create data in PHP is a lot harder than trying to manipulate or display it.… Read the rest

Read More