Im Not Playing Any More

.. rantings and blog of Chris Williams @scampiuk

Tuesday, 18 May 2010 07:15

ExternalDB

Written by  Chris Williams
Rate this item
(2 votes)

ExternalDB Has Moved!

We've moved maintenance of ExternalDB over to mkali.net, we recommend updating your bookmarks.


Introduction

ExternalDB was created for internal use at HORIZONSolutions.tv to overcome a simple yet common problem - how to connect to an external database, or multiple external databases, for multiple components / plugins / modules without having to duplicate the connection details again and again.

We created a plugin, ExternalDB, which allowed us to set these connection details once and get on with it!  Because of the kind of work we do we often have to query multiple databases to retrieve things like tournament information, player rankings and other such things that can't be moved into the local dataset as you would want to in these situations.

It's such a useful tool to us know that we install it with nearly every Joomla! deployment that we do.

What it does do

What it does not do

  • Allow you to add external database connections into your components, plugin and modules
  • Control database connection details site-wide for all the components / modules / plugins that use ExternalDB
  • Set up multiple connections to multiple databases
  • Make other 3rd party components work with external databases without modification
  • Allow Joomla! to run off another database
  • Allow connections to non-MySQL databases


Installing and Configuring

  • Install the plugin in the usual way, then make sure you enable it!
  • In Plugin Manager, configure your external database details for the database(s) you need.
    • DSN: Your name for the database to be used later on
    • Hostname: Host where the MySQL server is
    • Port Number: Defaults to 3306, but can change if needed
    • Username / Password : Authentication details for the database
    • Database Name: Name of the MySQL database to use


Implementing

This is where most of the confusion is, by what I read in my email from people asking me how to use it!  This is a code solution to using external databases.  There is no way of using this without modifying some code.  That out of the way, here's how to use it in that code.

ExternalDB simply creates a new jDatabase object with your given connection details - nothing clever but simple to maintain connection details. Here's a sample of code from one of our components...


// Create new ExternalDB instance, using the details that we set earlier.  
// 'resultsDb' is what we called the DSN
$dbxo = new externaldatabase ( 'resultsDb' ); 

// Create a new jDatabase object, connected with the details from the above selected DSN. 
// We call ExternalDB objects $dbx just as a standard practice
$dbx = $dbxo->getDB ();

$sql = "SELECT * FROM sport WHERE site = 2"; // Some simple SQL..

// Now you use your ExternalDB object in exactly the same way as you would the regular DB object..
$dbx->setQuery ( $sql );
$dbx->query ();
$res = $dbx->loadAssocList ();

I hope this clears up things!  We'll be working on moving this over to 1.6 very soon.

Last modified on Friday, 24 December 2010 19:16
Chris Williams

Chris Williams

PHP programmer for a mere 6 years, I've worked on creating social communities and content management systems while teaching myself the language.   For the last few years I've worked on free-to-view and pay-per-view live streaming / in-demand streaming media sites 247.tv and livesquash.tv, We travel around the world filming live sporting events, often doing post-production work for TV in the process.

12 comments

  • «
  •  Start 
  •  Prev 
  •  1 
  •  2 
  •  Next 
  •  End 
  • »

Leave a comment

Make sure you enter the (*) required information where indicated.
Basic HTML code is allowed.

Chris Williams
Chris Williams
chris@imnotplayinganymore.com
PHP & Joomla! Developer
FacebookFlickrFollow @scampiuk on twitter

West Midlands Joomla! User Group logo
West Midlands Joomla! User Group is now up and running.

Me on Twitter

scampiuk: Fuck me a try he didn't fuck up with theatrics. #6nations
scampiuk: RT @GreggCarter: RT @JoeSOTL Jesus Christ Barnes. How long do you want to leave before the................................ Engage! #6Nations
scampiuk: What is the recent trend to take an age to call the scrum? It's got the word 'pause' in it, don't add three pauses as well? #6nations
A coffee is always welcome, or maybe some pennies to charge the laptop.
They also pay for flowers for my wife so she doesn't hate me spending so much time on the computer...

Hosted by...

Dreamhost - a nice host

Get a free domain and up to 50% off registration costs! use the promo code CHRISWDISCOUNT

You are here: