Database connection with Firebird Adapter in Zend Framework

浪子不回头ぞ 提交于 2019-12-10 14:31:47

问题


I just started to learn about ZF and Firebird because of a project I am assigned to. I have been trying to make the connection between both for several days now, but I haven't succeed yet. I tried ZF with PDO_Mysql and it works just fine as it does Firebird connection with PHP (out of ZF), but when I try to make the connection with the Firebird adapter in ZF it keeps displaying all kinds of errors.

So, just to check. To make the connection in ZF with Firebird it should be done with the the adapter (Firebird.php) which I have configure in application.ini? I have something like this in the application.ini:

**resources.db.adapter = "Firebird"
resources.db.params.host = "localhost"
resources.db.params.dbname =  "C:/wamp/www/WebTH/application/data/THDATA.gdb"
resources.db.params.username = "sysdba"
resources.db.params.password = "masterkey"**

Resulting error: ...Firebird.php): failed to open stream: No such file or directory in ...\Loader.php

I have also seen that a function needs to be added in the Bootstrap.php. If I add the function initDb in the bootstrap.php like this:

 **protected function _initDb()
{
    $this->bootstrap('config');
    $config = $this->getResource('config');
    $db = Zend_Db::factory('Firebird', array(
        'host' => $config->Database->Server,
        'username' => $config->Database->Username,
        'password' => $config->Database->Password,
        'dbname' => $config->Database->DBName,
        'adapterNamespace' => 'ZendX_Db_Adapter'
    ));
    return $db;
}**

I get the error: ...Uncaught exception 'Zend_Application_Bootstrap_Exception' with message 'Resource matching "config" not found' in ...\BootstrapAbstract.php

I would like to know what do I really need to do in order to make the connection work. Sorry if this is too obvious, but I haven't been able to find a basic connection case specific for Zend Framework and Firebird, therefore I am not really sure on what I should do and where I should go.


回答1:


[Disclosure: I've never used the Firebird db.]

As you are probably aware, the Firebird adapter does not ship as part of the core ZF1 package. Looks like you can pull it from extras under the ZendX prefix:

http://framework.zend.com/svn/framework/extras/trunk/library/ZendX/Db/Adapter/

Drop the Firebird.php and Firebird/ files into a directory library/ZendX/Db/Adapter/.

If your application.ini uses the resources.db.* keys, then there is no need for an _initDb() method in your Bootstrap class. Just make sure that you include the adapterNamespace key in there, as well:

resources.db.params.adapterNamespace = "ZendX_Db_Adapter_"

You might also need to add the ZendX prefix to your autoloader namespaces:

autoloaderNamespaces[] = "ZendX_"

Not tested, but something like this should work.



来源:https://stackoverflow.com/questions/14123251/database-connection-with-firebird-adapter-in-zend-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!