开发者

How can use two database in same project in zend framework

I have a project in Zend Framework. I want call two database in same project, meaning I want to get values from the second database in the same project.

Please post step by step instruction with code and filename on开发者_运维问答 how to connect to the two databases.

There is a related question here connecting to two different databases with Zend Framework but I could not understand the code. Can someone please post mor information about this topic.


The answer to the other question is mostly self-descriptive * connecting to two different databases with Zend Framework

In the first codeblock, two database connections are created with names 'db' and 'db2', and they are added to the Registry

In the second block, the connections are picked from the Registry


    public function init()
    {
         $this->db = Zend_Registry::get('db');
         $this->db2 = Zend_Registry::get('db2');
    }

You can then run your queries on the fetched objects.

To use this code

  • Copy the first code block and put it in "bootstrap.php"
  • Modify the necessary hostnames, database names and passwords
  • use the second code block in your app code/logic

    Read more on Zend_Registry here http://framework.zend.com/manual/en/zend.registry.using.html

  • 0

    上一篇:

    下一篇:

    精彩评论

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

    最新问答

    问答排行榜