English 中文(简体)
如何在一个文件中连接 zend_ Db
原标题:how to connect zend_Db in one file

当我想将 zend 框架中的数据库与 zend_Db 连接到 zend_Db 中时, 在每个控制器或模型中必须写入此代码 :

$params = array(
 host            =>  127.0.0.1 ,
 username        =>  webuser ,
 password        =>  xxxxxxxx ,
 dbname          =>  test ,
 charset         =>  utf8 
);

但当使用“理论”时,只需在应用中写入此代码即可。 ini

doctrine.dsn = "mysql://user:pass@localhost/dbase"

我如何使用 zend_ Db 在每个文件中设置连接设置?

最佳回答

打开

application/configs/application.ini

添加以下条目

resources.db.adapter = PDO_MYSQL
resources.db.isDefaultAdapter = true
resources.db.params.host = localhost
resources.db.params.username = root
resources.db.params.password = 
resources.db.params.dbname = foo

然后在你的布斯陷阱.php内

do do do 做

public function _initSetup()
{
$this->bootstrap( db );
}

然后,无论何时或何时,只要您需要 db 示例 do do 做

$db = Zend_Db_Table::getDefaultAdapter();
问题回答

there are two ways one by using your configuration.ini file by this code :

resources.db.adapter = PDO_MYSQL
resources.db.params.host = localhost
resources.db.params.username = root
resources.db.params.password =   
resources.db.params.dbname = dbname
resources.db.params.driver_options.1002 = "SET NAMES utf8;"

或使用 hte 适配器类

$db = new Zend_Db_Adapter_Pdo_Mysql(array(
     host      =>  127.0.0.1 ,
     username  =>  webuser ,
     password  =>  xxxxxxxx ,
     dbname    =>  test 
));

并且不将任何函数放入您的 靴套.php 文件





相关问题
Zend 邮件问题,涉及外国char子+ com子

泽斯德邮局在名称被定为具有外国性质(如“保”)和 com(”)的物品时,就放弃了一种例外(因为邮局(邮局)退回假)。 重新提出以下守则。

PHP Framework: Ebay Like Site

I am going to be builiding a site like ebay - with all the features of ebay. Please note my payment method is limited to paypal. What would be the best PHP framework to use to build this quickly, ...

Link to a specific step in onepage checkout

Is it possible to redirect the browser to nth step in the onepage checkout? If so, how would one go about doing it? I m working on a payment module and have a sort of "cancel" action that i would ...

Tagging with Zend Framework

I m trying to create the same solutions as below, but using a simple MySQL query (instead of the static version used below where the words/tags are implemented in the code). The name of the MySQL ...

dynamicaly adding textboxes to zend_form

I hope that this is a quick question to answer. I am developing a form using Zend_Form, I have a number of Zend_Dojo_Form_Element_Textboxs to add to this form dynamically. These are added from rows ...

热门标签