0

我正在尝试在 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:\xampp\php\pear\Zend\Db\Table\Abstract.php(739): Zend_Db_Table_Abstract->_setupDatabaseAdapter()
#1 D:\xampp\php\pear\Zend\Db\Table\Abstract.php(268): Zend_Db_Table_Abstract->_setup()
#2 D:\xampp\htdocs\test\application\controllers\IndexController.php(14): Zend_Db_Table_Abstract->__construct()
#3 D:\xampp\php\pear\Zend\Controller\Action.php(516): IndexController->indexAction()
#4 D:\xampp\php\pear\Zend\Controller\Dispatcher\Standard.php(295): Zend_Controller_Action->dispatch('indexAction')
#5 D:\xampp\php\pear\Zend\Controller\Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#6 D:\xampp\php\pear\Zend\Application\Bootstrap\Bootstrap.php(97): Zend_Controller_Front->dispatch()
#7 D:\xampp\php\pear\Zend\Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#8 D:\xampp\htdocs\test\public\index.php(26): Zend_Application->run()
#9 {main}  

Request Parameters:

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

连接需要更多更改吗?

4

2 回答 2

3

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

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 ");

希望能帮助到你。

于 2013-06-21T20:55:03.120 回答
1

尝试将您的 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
于 2013-06-21T20:12:56.657 回答