开发者

(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? I don't want to extend my model with Zend_Db_Table, it seems pretty useless for me at the moment.

Sorry for question, but I'm real noob in 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. 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.

If you don't care about compatibility with the Zend_Db package, you just use DBSimple like you always do. 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. See the chapter on Zend_Application in the reference guide for more details on how to do this.


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;

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜