繁体   English   中英

Zend_db只在我的主模块中出错,并且只有当我使用'woningen'作为表名时

[英]Zend_db only gives a error in my main module and only when I use 'woningen' as table name

这是我用来更新/插入数据库中的数据的代码。

public function saveItem($post, $table)
    {
        unset($post['submit']);
        $this->_table = new Zend_Db_Table($table); exit;

        if (isset($post['id'])) {
            $where = $this->_table->getAdapter()->quoteInto('id = ?', $post['id']);
            $this->_table->update($post, $where);
            return $post['id'];
        } else {
            return $this->_table->insert($post);
        }
    }

由于某些原因

$this->_table = new Zend_Db_Table($table);

给我一个错误,但只有当$ table ='woningen'并且仅在我的主模块中。

这是错误:

APPLICATION ERROR
EXCEPTION INFORMATION:
Message: Argument must be of type Zend_Db_Adapter_Abstract, or a Registry key where a Zend_Db_Adapter_Abstract object is stored
STACK TRACE:
#0 D:\xampp\htdocs\makeltrent.website\library\Zend\Db\Table\Abstract.php(581): Zend_Db_Table_Abstract::_setupAdapter('woningen')
#1 D:\xampp\htdocs\makeltrent.website\library\Zend\Db\Table\Abstract.php(283): Zend_Db_Table_Abstract->_setAdapter('woningen')
#2 D:\xampp\htdocs\makeltrent.website\library\Zend\Db\Table\Abstract.php(265): Zend_Db_Table_Abstract->setOptions(Array)
#3 D:\xampp\htdocs\makeltrent.website\library\Zend\Db\Table.php(77): Zend_Db_Table_Abstract->__construct(Array)
#4 D:\xampp\htdocs\makeltrent.website\application\models\Inlog.php(109): Zend_Db_Table->__construct('woningen')
#5 D:\xampp\htdocs\makeltrent.website\application\modules\default\controllers\WoningmandjeController.php(157): Application_Model_Inlog->saveItem(Array, 'woningen')
#6 D:\xampp\htdocs\makeltrent.website\library\Zend\Controller\Action.php(516): WoningmandjeController->sendAction()
#7 D:\xampp\htdocs\makeltrent.website\library\Zend\Controller\Dispatcher\Standard.php(295): Zend_Controller_Action->dispatch('sendAction')
#8 D:\xampp\htdocs\makeltrent.website\library\Zend\Controller\Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#9 D:\xampp\htdocs\makeltrent.website\library\Zend\Application\Bootstrap\Bootstrap.php(97): Zend_Controller_Front->dispatch()
#10 D:\xampp\htdocs\makeltrent.website\library\Zend\Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#11 D:\xampp\htdocs\makeltrent.website\public\index.php(26): Zend_Application->run()
#12 {main} 

我的第一个想法,正如错误消息所解释的那样,你有一个名称的Zend_Registry键,但不是像Zend_Db_Adapter_Pdo_Mysql这样的对象,这正是它所期望的。 随机字符串不会因为这个原因而失败,因为它最终会返回falsenull - 它只是返回_setupAdapter函数而不做任何事情。

我认为这是你的课程设置的一个问题。

Zend_Db_Table 需要DB Adapter才能初始化Tablename。 您可以在application.ini中将适配器定义为默认数据库适配器。

resources.db.adapter = "PDO_MYSQL"
resources.db.params.host = "host"
resources.db.params.dbname = "database"
resources.db.params.username = "user"
resources.db.params.password = "password"
resources.db.isDefaultTableAdapter = true

暂无
暂无

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

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