2013-08-02 72 views
0

我有一個關於zend框架的問題。我有一個網站的源文件,它是使用php & zend framework & MySQL開發的。本網站以前由其他人開發。我想在我的電腦上本地運行這些文件,以便我可以對網站進行更改。我安裝了XAMPP和PHP,但是當我嘗試運行它,錯誤出在瀏覽器上:在本地運行php zend框架

Fatal error: Uncaught exception 'Zend_Db_Adapter_Exception' with message 'SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES)' in C:\xampp\htdocs\www\medicatoz\library\Zend\Db\Adapter\Pdo\Abstract.php:143 
Stack trace: 
#0 C:\xampp\htdocs\www\medicatoz\library\Zend\Db\Adapter\Abstract.php(441): Zend_Db_Adapter_Pdo_Abstract->_connect() 
#1 C:\xampp\htdocs\www\medicatoz\library\Zend\Db\Adapter\Pdo\Abstract.php(230): Zend_Db_Adapter_Abstract->query('SET NAMES UTF8', Array) 
#2 C:\xampp\htdocs\www\medicatoz\conf\bootstrap.php(63): Zend_Db_Adapter_Pdo_Abstract->query('SET NAMES UTF8') #3 C:\xampp\htdocs\www\medicatoz\index.php(4): require('C:\xampp\htdocs...') #4 {main} thrown in C:\xampp\htdocs\www\medicatoz\library\Zend\Db\Adapter\Pdo\Abstract.php on line 143 

你們能幫助我弄清楚什麼是這個錯誤呢?我懷疑它可能是分貝,但我不知道具體。我希望也許有人遇到這個錯誤之前可以給我一個想法。提前致謝。

嗨,大家好, 我想你的建議,似乎我通過數據庫的一部分。但現在它顯示此錯誤:

Array([0] => Zend_Controller_Dispatcher_Exception Object([message:protected] =>指定的無效控制器(www)[string:Exception:private] => [code:protected] => 0 [file:protected] => C:\ xampp \ htdocs \ www \ library \ Zend \ Controller \ Dispatcher \ Standard.php [line:protected] => 241 [trace:Exception:private] => Array([0] => Array [(file] => C:\ xampp \ htdocs \ www \ library \ Zend \ Controller \ Front.php [line] => 936 [function] => dispatch [class] => Zend_Controller_Dispatcher_Standard [type] => - > [args] => Array([0] => Zend_Controller_Request_Http Object([_paramSources:protected] => Array([0] => _GET [1] => _POST)[_requestUri:protected] =>/www/web /themes/medicatoz/index.phtml [_baseUrl:protected] => [_basePath:protected] => [_pathInfo:protected] => /www/web/themes/medicatoz/index.phtml [_params:protected] => Array( [控制器] => [_module:protected] => default [_moduleKey:protected] ] => module [_controller:protected] => www [_controllerKey:protected] => controller [_action:protected] => web [_actionKey:protected] => action)[1] => Zend_Controller_Response_Http Object([_body:protected] =>數組()[_exceptions:保護] =>數組遞推 [_headers:保護] =>數組()[_headersRaw:保護] =>數組()[_httpResponseCode:保護] => 200 _isRedirect:保護] = > [1] =>數組([文件] => C:\ xampp \ htdocs \ www \ index.php [line] => 5 [函數] =>調度[類] =>在Zend_Controller_Front [型] => - > [參數] =>數組()))[前:異常:私人] =>))

我認爲這表明訪問存在一些限制,阻止它顯示正確的網站。任何想法如何克服這一點?感謝您的耐心和幫助。

+1

'拒絕訪問用戶「根」 @「localhost''是問題的根源。你有數據庫設置嗎?它配置正確嗎? –

+0

您是否嘗試過使用用戶名和密碼登錄mysql的文件? mysql -u root -p並鍵入密碼。也嘗試登錄沒有密碼。這很可能是密碼問題 –

+0

@Pekka'root'@'localhost'是問題的根源。潘本意;)? –

回答

0

檢查對您的數據庫確保你的訪問,獲取數據庫名稱,用戶名和密碼來訪問數據庫,並修改代碼如果您使用Zend框架1.XX
如下

轉到PROJECT_DIR /應用/配置/的application.ini

resources.db.adapter = "pdo_mysql" 
resources.db.params.host = "localhost" 
resources.db.params.username = "DB_USERNAME" 
resources.db.params.password = "DB_PASSWORD" 
resources.db.params.dbname = "DB_NAME" 
resources.db.idDefaultTableAdapter = true 

如果Zend框架2.xx的
轉到PROJECT_DIR/config/autoload/global.php ,你也可以檢查local.php中自動加載文件夾

return array(
    'db' => array(
     'driver' => 'Pdo', 
     'dsn' => 'mysql:dbname=DB_NAME;host=localhost', 
     'username' => 'DB_USERNAME', 
     'password' => 'DB_PASSWORD', 
     'driver_options' => array(
      PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\'' 
     ), 
    ), 
    .... 
); 
1

把你的代碼放在文件夾的config /自動加載

創建兩個文件名當地。PHP把這段代碼

<?php 
return array(
    'db' => array(
     'username' => 'root', 
     'password' => '', 
    ), 
); 

另一個文件database.local.php發佈此代碼

<?php 

return array(
    'db' => array(
     'driver'   => 'Pdo', 
     'dsn'   => 'mysql:dbname=testdb;host=localhost', 
    ), 
    'service_manager' => array(
     'factories' => array(
     'Zend\Db\Adapter\Adapter' => 'Zend\Db\Adapter\AdapterServiceFactory', 
    ), 
    ), 
);