开发者

Using multiple databases with DooPHP

I'm checking out DooPHP and I can't seem to find how to use multiple database connections simultaneously. I just want to have multiple database objects and use their methods to query the DB. Now I I'm doing this:

Doo::db()->setDb($dbc开发者_Go百科onfig, $config['APP_MODE']);
Doo::db()->query('.......');

and then setDb again when I want to use another DB. This is retarded though. It's very difficult to find what you're looking for in the API documentation as well.

Any help here?


The solution was to do this in index.php:

Doo::loadCore('db/DooSqlMagic');
$db = new DooSqlMagic;
$db->setDb($dbconfig, 'db'.$config['APP_MODE']);
$db->connect();

$db2 = new DooSqlMagic;
$db2->setDb($dbconfig, 'db2'.$config['APP_MODE']);
$db2->connect();

This in db.conf.php:

$dbconfig['dbdev'] = array('localhost', 'db', 'root', '', 'mysql', true, 'collate'=>'utf8_unicode_ci', 'charset'=>'utf8');
$dbconfig['dbprod'] = array('localhost', 'db', 'root', '', 'mysql', true, 'collate'=>'utf8_unicode_ci', 'charset'=>'utf8');

$dbconfig['db2dev'] = array('localhost', 'db2', 'root', '', 'mysql', true, 'collate'=>'utf8_unicode_ci', 'charset'=>'utf8');
$dbconfig['db2prod'] = array('localhost', 'db2', 'root', '', 'mysql', true, 'collate'=>'utf8_unicode_ci', 'charset'=>'utf8');

And use it like this in the controller:

global $db;
global $db2;
$db->query('.......');
$db2->query('......');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜