Created
October 12, 2010 01:13
-
-
Save joshtronic/621498 to your computer and use it in GitHub Desktop.
Multiple Database Driver Support in PICKLES
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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