2010-08-14 39 views
3

通过zend教程工作&得到这个消息,&不知道在哪里看。zend新手问题 - “没有找到适配器”

感谢,

An error occurred 
Application error 
Exception information: 

Message: No adapter found for Model_DbTable_Books 
Stack trace: 

#0 C:\xampp\php\PEAR\Zend\Db\Table\Abstract.php(739): Zend_Db_Table_Abstract->_setupDatabaseAdapter() 
#1 C:\xampp\php\PEAR\Zend\Db\Table\Abstract.php(268): Zend_Db_Table_Abstract->_setup() 
#2 C:\xampp\htdocs\zftutorials\zftutorial\application\controllers\BooksController.php(34): Zend_Db_Table_Abstract->__construct() 
#3 C:\xampp\php\PEAR\Zend\Controller\Action.php(513): BooksController->listAction() 
#4 C:\xampp\php\PEAR\Zend\Controller\Dispatcher\Standard.php(289): Zend_Controller_Action->dispatch('listAction') 
#5 C:\xampp\php\PEAR\Zend\Controller\Front.php(946): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) 
#6 C:\xampp\php\PEAR\Zend\Application\Bootstrap\Bootstrap.php(77): Zend_Controller_Front->dispatch() 
#7 C:\xampp\php\PEAR\Zend\Application.php(358): Zend_Application_Bootstrap_Bootstrap->run() 
#8 C:\xampp\htdocs\zftutorials\zftutorial\public\index.php(26): Zend_Application->run() 
#9 {main} 

Request Parameters: 

array (
    'controller' => 'books', 
    'action' => 'list', 
    'module' => 'default', 
) 
+0

哪个Zend教程?介意发布一个链接到它? – 2010-08-14 00:56:59

+0

http://www.youtube.com/user/integral30#p/u/58/kuNNwpeNn4s 组好的教程,遗憾的是他并没有进入太多详细的数据库访问 – 2010-08-14 01:01:52

回答

8

要连接到数据库的使用:

$dbAdapter = Zend_Db::factory('Pdo_Mysql', array(
    'host'  => '127.0.0.1', 
    'username' => 'webuser', 
    'password' => 'xxxxxxxx', 
    'dbname' => 'test' 
)); 

并设置默认的适配器:

Zend_Db_Table::setDefaultAdapter($dbAdapter); 

有一些方法来设置特定适配器没有配置默认适配器等的表...

您可以在文档中看到更多的细节......请阅读:d

的[]

+0

仅供参考设置默认的适配器尤其是如果您正在为zend_application使用multiDb资源插件 – 2011-02-12 21:21:55

1

菲利普是正确的,而所需的教程此设立的application.ini文件。

resources.db.adapter = mysqli 
resources.db.params.host = localhost 
resources.db.params.username = user 
resources.db.params.password = pw 
resources.db.params.dbname = test 
3

添加以下应用程序文件夹内的引导文件代码:

protected function _initDB() { 

     $dbConfig = new Zend_Config_Ini(APPLICATION_PATH . '/configs/db.ini'); 
     $dbAdapter = Zend_Db::factory($dbConfig->adapter, array(
      'host'  => $dbConfig->hostname, 
      'username' => $dbConfig->username, 
      'password' => $dbConfig->password, 
      'dbname' => $dbConfig->dbname 
     )); 

     My_Db_Table_Abstract::setDefaultAdapter($dbAdapter); 

     Zend_Registry::set('db', $dbAdapter); 


     if (APPLICATION_ENV == 'development') { 
      $profiler = new Zend_Db_Profiler_Firebug('All DB Queries'); 
      $profiler->setEnabled(true); 
      $dbAdapter->setProfiler($profiler); 
     } 
    } 


     public function _initRouter() 
     { 
      $front = Zend_Controller_Front::getInstance(); 
      $router = $front->getRouter(); 

     } 

} 

和的application.ini文件下面的代码:

resources.db.adapter = mysqli 
resources.db.params.host = localhost 
resources.db.params.username = username of mysql(default root) 
resources.db.params.password = password of mysql(default blank means '') 
resources.db.params.dbname = test 

这不是配置问题数据库