简体   繁体   English

(Zend Framework 1.10)如何使用自定义数据库适配器?

[英](Zend Framework 1.10) How to use custom DB adapter?

How could I set up custom DB adapter (I will use simple DBSimple) and then use it inside of my model? 如何设置自定义数据库适配器(我将使用简单的DBSimple),然后在模型内部使用它? I don't want to extend my model with Zend_Db_Table, it seems pretty useless for me at the moment. 我不想使用Zend_Db_Table扩展我的模型,目前看来对我来说毫无用处。

Sorry for question, but I'm real noob in ZF. 抱歉,我是ZF的真正菜鸟。

Thank you 谢谢

If you really want to have a custom adapter in the ZF sense, you have to extend their Zend_Db_Adapter_Abstract class and implement all methods within for use with DBSimple. 如果您真的想使用ZF 定义自定义适配器 ,则必须扩展其Zend_Db_Adapter_Abstract类并实现其中的所有方法以与DBSimple一起使用。 If you do this, you can use the adapter with the entire Zend_Db package and you would also set it up like any other ZF adapter. 如果这样做,则可以将适配器与整个Zend_Db软件包一起使用,并且还可以像设置其他ZF适配器一样进行设置。

If you don't care about compatibility with the Zend_Db package, you just use DBSimple like you always do. 如果您不关心与Zend_Db软件包的兼容性,则可以像DBSimple一样使用DBSimple If you want to set it up during your app's bootstrap and you are using Zend_Application , either create a custom Resource Plugin or add an _initDb method in your Zend_Application_Bootstrap_Bootstrap . 如果你希望你的应用程序的引导过程中设置它,你正在使用Zend_Application ,或者创建自定义资源插件或添加_initDb在你的方法Zend_Application_Bootstrap_Bootstrap See the chapter on Zend_Application in the reference guide for more details on how to do this. 有关如何执行此操作的更多详细信息,请参见参考指南中有关Zend_Application的章节

try this, creat a model class 试试这个,创建一个模型类

function __construct(){
    $this->select = new Zend_Db_Select(Zend_Db_Table::getDefaultAdapter());
}
//creat a function to use the db connection created in the __construct function
public function getDatabaseRow(){ 

    $select= $this->select
            ->from('TableName')
             ->where ('columnName =?','$option')

     $query = $select->query(); 
     $rows = $query->fetchAll();

    return $rows;
}

} }

u can now iterate thru the rows; 您现在可以遍历行;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM