zend框架数据库连接无法正常工作

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了zend框架数据库连接无法正常工作相关的知识,希望对你有一定的参考价值。

我试图在zend框架中进行数据库连接

下面是我的application.ini

[production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 1
database.adapter            =   pdo_mysql
database.params.host        =   localhost
database.params.username    =   root
database.params.password    =   
database.params.dbname      =   test
resources.db.isDefaultTableAdapter = true

[staging : production]

[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1

[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1 

低于错误

Message: No adapter found for Application_Model_DbTable_User
Stack trace:

#0 D:xamppphppearendDbTableAbstract.php(739): Zend_Db_Table_Abstract->_setupDatabaseAdapter()
#1 D:xamppphppearendDbTableAbstract.php(268): Zend_Db_Table_Abstract->_setup()
#2 D:xampphtdocs	estapplicationcontrollersIndexController.php(14): Zend_Db_Table_Abstract->__construct()
#3 D:xamppphppearendControllerAction.php(516): IndexController->indexAction()
#4 D:xamppphppearendControllerDispatcherStandard.php(295): Zend_Controller_Action->dispatch('indexAction')
#5 D:xamppphppearendControllerFront.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#6 D:xamppphppearendApplicationBootstrapBootstrap.php(97): Zend_Controller_Front->dispatch()
#7 D:xamppphppearendApplication.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#8 D:xampphtdocs	estpublicindex.php(26): Zend_Application->run()
#9 {main}  

Request Parameters:

array (
  'controller' => 'index',
  'action' => 'index',
  'module' => 'default',
)  

连接需要进行更改吗?

答案

我认为您需要添加“资源”并将值放在“”之间。

resources.db.adapter = "pdo_mysql"
resources.db.params.host = "localhost"
resources.db.params.port = 3306
resources.db.params.username = "root"
resources.db.params.password = ""
resources.db.params.dbname = "test"
resources.db.isDefaultTableAdapter = true

并调用您的适配器(在您的课程内)

$db = Zend_Db_Table::getDefaultAdapter();
 // Example of selcting all contacts from the database 
$contacts = $db->fetchAll("SELECT * FROM contacts ");

希望能帮助到你。

另一答案

尝试将您的INI文件更改为:

resources.db.adapter            =   pdo_mysql
resources.db.params.host        =   localhost
resources.db.params.username    =   root
resources.db.params.password    =   
resources.db.params.dbname      =   test

以上是关于zend框架数据库连接无法正常工作的主要内容,如果未能解决你的问题,请参考以下文章

nginx 上的 Zend 框架

Zend 框架中无法回滚事务

在 zend 框架中填充子表单的问题

带有复选框和自定义适配器的 ListView,片段无法正常工作

无法从 onListItemClick 开始片段

使用片段共享过渡时返回过渡无法正常工作