开发者

How I will access a table from another Databse in cakephp

I have two database in my project. I have declared two connection variable in database.php. As follows:

var $development = array(

        'driver' => 'mysql',
        'persistent' => false,
        'host' => 'xxxx',
        'login' => 'xxxx',
        'password' => 'xxxx',
        'database' => 'yyyy',
        'prefix' => '',
    );
    var $production = array(
        'driver' => 'mysql',
        'persistent' => false,
        'host' => 'xxxxxx',
        'login' => 'xx',
        'password' => 'xx',
        'database' => 'xxx',
        'prefix' => '',
);

Now I am using the development as the default connection.

In one controller function I need to fetch some values from the anther DB. How can I get the other DB data there? If any body can help regarding this I will very very obiliged to him/her. Thank you in adv开发者_运维百科ance .


you can use $useDbConfig in your model class to define which database should it use for data source

class Example extends AppModel {
    var $useDbConfig = 'development';
}

class Example extends AppModel {
    var $useDbConfig = 'production';
}

and you can check the detail usage in cakephp document

http://book.cakephp.org/view/1057/Model-Attributes

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜