duanquannan0593 2013-06-21 20:09
浏览 40
已采纳

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

I am try to do database connection in zend framework

Below is my 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 

Getting below error

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',
)  

any more changes is required for connection?

  • 写回答

2条回答 默认 最新

  • duanhuan6336 2013-06-21 20:55
    关注

    I Think you need need add "resource " and put values between " ".

    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
    

    And to call your Adapter ( inside your classes )

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

    hope it helps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化