Skip to content

Instantly share code, notes, and snippets.

@joshtronic
Created October 12, 2010 01:13
Show Gist options
  • Save joshtronic/621498 to your computer and use it in GitHub Desktop.
Save joshtronic/621498 to your computer and use it in GitHub Desktop.
Multiple Database Driver Support in PICKLES
[DATABASE]
default = DBMS
[DBMS]
driver = mysql
hostname = localhost
username = username
password = password
database = database
[NOSQL]
driver = mongo
hostname = localhost
username = username
password = password
database = database
<?php
class module extends Module
{
public function __default()
{
// First thoughts:
$this->db->DBMS->fetch('SELECT ...');
$this->db->NOSQL->findOne(...);
// Better layout with an array:
$this->db['DBMS']->fetch('SELECT ...');
$this->db['NOSQL']->findOne(...);
// More coding, but could use the factory pattern
$mysql = new Database('DBMS');
$mysql->fetch('SELECT ...');
// Or... Would it just be better to call the classes by name?
$mongo = new Mongo('NOSQL');
$mongo->findOne(...);
// Maybe leave $this->db as is using the default defined in [DATABASE]
// as to not punish folks with a single database rig (majority?)
$this->db->fetch('SELECT ...');
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment