【问题标题】:Zend database connectivityZend 数据库连接
【发布时间】:2011-08-24 16:46:37
【问题描述】:

我在我的用户控制器中使用了这个

require_once 'Zend/Controller/Action.php';

public function processAction()
 {

   $params = array('host'       =>'localhost',
                'username'  =>'root',
                'password'  =>'',
                'dbname'    =>'zend'
               );

   $DB = new Zend_Db_Adapter_Pdo_Mysql($params);

   $request = $this->getRequest();
   $data = array('first_name' => $request->getParam('first_name'),
              'last_name' => $request->getParam('last_name'),
              'user_name' => $request->getParam('user_name'),
              'password' => md5($request->getParam('password'))
              );
   $DB->insert('user', $data);

   $this->view->assign('title','Registration Process');
   $this->view->assign('description','Registration succes');    

 }

显示以下错误。我没有 php.ini 访问权限。

致命错误:第 42 行的 D:\xampp\xampp\htdocs\zend-test\zend-demo\application\controllers\UserController.php 中未找到 Class 'Zend_Db'

即在这条线上

$params = Zend_Db::factory('Pdo_Mysql', array(
    'host'     => 'localhost',
    'username' => 'root',
    'password' => '',
     'dbname'   => 'zend'
));

提前致谢!

  • 曼格什

【问题讨论】:

  • 问题似乎是 php.ini 的 include_path 中没有包含 Zend 库。另外我建议将数据库连接移动到 /configs/application.ini 文件和 index.php 中,如果选项加载了 // Create application, bootstrap, and run $application = new Zend_Application( APPLICATION_ENV, APPLICATION_PATH . '/configs/应用程序.ini');

标签: database zend-framework


【解决方案1】:

也许这会有所帮助。

关于如何设置一个有效的 Zend 框架的教程

http://usingzendframework.blogspot.com/2007/01/setting-up-zend-framework.html

【讨论】:

    【解决方案2】:

    您需要包含您使用的所有 Zend 库 - 而不仅仅是

    equire_once 'Zend/Controller/Action.php';
    

    此外,您需要执行 Jurka 指定的操作 - 一种更好、更清洁的做法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-10
      • 2010-12-12
      相关资源
      最近更新 更多