致命错误:未捕获的异常' Zend_Db_Table_Exception'

时间:2014-03-06 06:43:02

标签: php mysql .htaccess zend-framework

我正在使用zend1.12。我将index.php从public文件放到root文件夹中,并在更改错误之后更改了配置。

我收到以下错误,所有配置看起来都很好。

Fatal error: Uncaught exception 'Zend_Db_Table_Exception' with message 'No adapter found for Application_Model_Content' in /var/www/html/library/Zend/Db/Table/Abstract.php:756 Stack trace: #0 /var/www/html/library/Zend/Db/Table/Abstract.php(740): Zend_Db_Table_Abstract->_setupDatabaseAdapter() #1 /var/www/html/library/Zend/Db/Table/Abstract.php(269): Zend_Db_Table_Abstract->_setup() #2 /var/www/html/library/Zend/Db/Table.php(77): Zend_Db_Table_Abstract->__construct(Array) #3 /var/www/html/application/views/scripts/common/topnav.phtml(2): Zend_Db_Table->__construct() #4 /var/www/html/library/Zend/View.php(108): include('/var/www/html/a...') #5 /var/www/html/library/Zend/View/Abstract.php(888): Zend_View->_run('/var/www/html/a...') #6 /var/www/html/application/layouts/scripts/front_header.phtml(29): Zend_View_Abstract->render('common/topnav.p...') #7 /var/www/html/library/Zend/View.php(108): include('/var/www/html/a...') #8 /var/www/html/library/Zend/View/Abstract.php(888): Zend_View->_run('/var/www/html/a...') #9 /var/www/ in /var/www/html/library/Zend/Controller/Plugin/Broker.php on line 336

以下是application / configs / applicatio.ini文件

[production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
includePaths.library = BASE_PATH "/library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 1

resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"

resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"
resources.frontController.baseUrl = "/"

resources.session.remember_me_seconds = 864000

[staging : production]

[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.db.adapter = "PDO_MYSQL"
resources.db.params.host = "localhost"
resources.db.params.username = "root"
resources.db.params.password = "root123"
resources.db.params.dbname = "labs"
resources.db.isDefaultTableAdapter = true

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

resources.db.params.profiler.enabled = true
resources.db.params.profiler.class = Zend_Db_Profiler_Firebug

的index.php

<?php
date_default_timezone_set('Indian/Mahe');
// Define path to application directory
define('BASE_PATH', realpath(dirname(__FILE__)));

defined('APPLICATION_PATH')
   || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/application'));

// Define application environment
defined('APPLICATION_ENV')
    || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'testing'));


// Include path
set_include_path(
    BASE_PATH . '/library' 
   /*. PATH_SEPARATOR . '../Zend' */   
    . PATH_SEPARATOR . get_include_path()
);

/** Zend_Application */
require_once 'Zend/Application.php';
// Create application, bootstrap, and run

$application = new Zend_Application(
    APPLICATION_ENV,
    APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap()
            ->run();
Zend_Db_Table::getDefaultAdapter();

/application/bootstrap.php

<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{    
    protected function _initMyDb() {

    $this->bootstrap('db');
    $resource = $this->getPluginResource('db');
    $db = $resource->getDbAdapter();

   //$db->query('SET CHARACTER SET \'UTF8\'');
}

protected function _initRegistry()
{
    $this->bootstrap('db');
    $db = $this->getResource('db');
   // $db->query("SET NAMES 'utf8'");
}
}

1 个答案:

答案 0 :(得分:0)

您将适配器设置为[testing: production]

[testing : production]
...
resources.db.adapter = "PDO_MYSQL"
resources.db.params.host = "localhost"
resources.db.params.username = "root"
resources.db.params.password = "root123"
resources.db.params.dbname = "labs"
resources.db.isDefaultTableAdapter = true

您是否已加入.htaccess SetEnv APPLICATION_ENV testing 或者这是一个错误,您应该在[production]

中逐出