Я работаю над официальным учебником для ZF2 .
В конце страницы, чтобы узнать, что дает результат, я получаю эту длинную ошибку:
An error occurred An error occurred during execution; please try again later. Additional information: Zend\Db\Adapter\Exception\RuntimeException File: D:\softs\UwAmp\www\zf2-tutorial\ZendSkeletonApplication\vendor\zendframework\zendframework\library\Zend\Db\Adapter\Driver\Pdo\Connection.php:243 Message: Connect Error: SQLSTATE[28000] [1045] Access denied for user ''@'localhost' (using password: NO) Stack trace: #0 D:\softs\UwAmp\www\zf2-tutorial\ZendSkeletonApplication\vendor\zendframework\zendframework\library\Zend\Db\Adapter\Driver\Pdo\Pdo.php(211): Zend\Db\Adapter\Driver\Pdo\Connection->connect() #1 D:\softs\UwAmp\www\zf2-tutorial\ZendSkeletonApplication\vendor\zendframework\zendframework\library\Zend\Db\Adapter\Adapter.php(175): Zend\Db\Adapter\Driver\Pdo\Pdo->createStatement(NULL) #2 D:\softs\UwAmp\www\zf2-tutorial\ZendSkeletonApplication\vendor\zendframework\zendframework\library\Zend\Db\Sql\Sql.php(103): Zend\Db\Adapter\Adapter->createStatement() #3 D:\softs\UwAmp\www\zf2-tutorial\ZendSkeletonApplication\vendor\zendframework\zendframework\library\Zend\Db\TableGateway\AbstractTableGateway.php(234): Zend\Db\Sql\Sql->prepareStatementForSqlObject(Object(Zend\Db\Sql\Select)) #4 D:\softs\UwAmp\www\zf2-tutorial\ZendSkeletonApplication\vendor\zendframework\zendframework\library\Zend\Db\TableGateway\AbstractTableGateway.php(210): Zend\Db\TableGateway\AbstractTableGateway->executeSelect(Object(Zend\Db\Sql\Select)) #5 D:\softs\UwAmp\www\zf2-tutorial\ZendSkeletonApplication\vendor\zendframework\zendframework\library\Zend\Db\TableGateway\AbstractTableGateway.php(197): Zend\Db\TableGateway\AbstractTableGateway->selectWith(Object(Zend\Db\Sql\Select)) #6 D:\softs\UwAmp\www\zf2-tutorial\ZendSkeletonApplication\module\Album\src\Album\Model\AlbumTable.php(24): Zend\Db\TableGateway\AbstractTableGateway->select() #7 D:\softs\UwAmp\www\zf2-tutorial\ZendSkeletonApplication\module\Album\src\Album\Controller\AlbumController.php(18): Album\Model\AlbumTable->fetchAll() #8 D:\softs\UwAmp\www\zf2-tutorial\ZendSkeletonApplication\vendor\zendframework\zendframework\library\Zend\Mvc\Controller\AbstractActionController.php(87): Album\Controller\AlbumController->indexAction() #9 [internal function]: Zend\Mvc\Controller\AbstractActionController->onDispatch(Object(Zend\Mvc\MvcEvent)) #10 D:\softs\UwAmp\www\zf2-tutorial\ZendSkeletonApplication\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(469): call_user_func(Array, Object(Zend\Mvc\MvcEvent)) #11 D:\softs\UwAmp\www\zf2-tutorial\ZendSkeletonApplication\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(209): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure)) #12 D:\softs\UwAmp\www\zf2-tutorial\ZendSkeletonApplication\vendor\zendframework\zendframework\library\Zend\Mvc\Controller\AbstractController.php(108): Zend\EventManager\EventManager->trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure)) #13 D:\softs\UwAmp\www\zf2-tutorial\ZendSkeletonApplication\vendor\zendframework\zendframework\library\Zend\Mvc\DispatchListener.php(114): Zend\Mvc\Controller\AbstractController->dispatch(Object(Zend\Http\PhpEnvironment\Request), Object(Zend\Http\PhpEnvironment\Response)) #14 [internal function]: Zend\Mvc\DispatchListener->onDispatch(Object(Zend\Mvc\MvcEvent)) #15 D:\softs\UwAmp\www\zf2-tutorial\ZendSkeletonApplication\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(469): call_user_func(Array, Object(Zend\Mvc\MvcEvent)) #16 D:\softs\UwAmp\www\zf2-tutorial\ZendSkeletonApplication\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(209): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure)) #17 D:\softs\UwAmp\www\zf2-tutorial\ZendSkeletonApplication\vendor\zendframework\zendframework\library\Zend\Mvc\Application.php(298): Zend\EventManager\EventManager->trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure)) #18 D:\softs\UwAmp\www\zf2-tutorial\ZendSkeletonApplication\public\index.php(12): Zend\Mvc\Application->run() #19 {main} Previous exceptions: PDOException File: D:\softs\UwAmp\www\zf2-tutorial\ZendSkeletonApplication\vendor\zendframework\zendframework\library\Zend\Db\Adapter\Driver\Pdo\Connection.php:239 Message: SQLSTATE[28000] [1045] Access denied for user ''@'localhost' (using password: NO) Stack trace: #0 D:\softs\UwAmp\www\zf2-tutorial\ZendSkeletonApplication\vendor\zendframework\zendframework\library\Zend\Db\Adapter\Driver\Pdo\Connection.php(239): PDO->__construct('mysql:dbname=zf...', NULL, NULL, Array) #1 D:\softs\UwAmp\www\zf2-tutorial\ZendSkeletonApplication\vendor\zendframework\zendframework\library\Zend\Db\Adapter\Driver\Pdo\Pdo.php(211): Zend\Db\Adapter\Driver\Pdo\Connection->connect() #2 D:\softs\UwAmp\www\zf2-tutorial\ZendSkeletonApplication\vendor\zendframework\zendframework\library\Zend\Db\Adapter\Adapter.php(175): Zend\Db\Adapter\Driver\Pdo\Pdo->createStatement(NULL) #3 D:\softs\UwAmp\www\zf2-tutorial\ZendSkeletonApplication\vendor\zendframework\zendframework\library\Zend\Db\Sql\Sql.php(103): Zend\Db\Adapter\Adapter->createStatement() #4 D:\softs\UwAmp\www\zf2-tutorial\ZendSkeletonApplication\vendor\zendframework\zendframework\library\Zend\Db\TableGateway\AbstractTableGateway.php(234): Zend\Db\Sql\Sql->prepareStatementForSqlObject(Object(Zend\Db\Sql\Select)) #5 D:\softs\UwAmp\www\zf2-tutorial\ZendSkeletonApplication\vendor\zendframework\zendframework\library\Zend\Db\TableGateway\AbstractTableGateway.php(210): Zend\Db\TableGateway\AbstractTableGateway->executeSelect(Object(Zend\Db\Sql\Select)) #6 D:\softs\UwAmp\www\zf2-tutorial\ZendSkeletonApplication\vendor\zendframework\zendframework\library\Zend\Db\TableGateway\AbstractTableGateway.php(197): Zend\Db\TableGateway\AbstractTableGateway->selectWith(Object(Zend\Db\Sql\Select)) #7 D:\softs\UwAmp\www\zf2-tutorial\ZendSkeletonApplication\module\Album\src\Album\Model\AlbumTable.php(24): Zend\Db\TableGateway\AbstractTableGateway->select() #8 D:\softs\UwAmp\www\zf2-tutorial\ZendSkeletonApplication\module\Album\src\Album\Controller\AlbumController.php(18): Album\Model\AlbumTable->fetchAll() #9 D:\softs\UwAmp\www\zf2-tutorial\ZendSkeletonApplication\vendor\zendframework\zendframework\library\Zend\Mvc\Controller\AbstractActionController.php(87): Album\Controller\AlbumController->indexAction() #10 [internal function]: Zend\Mvc\Controller\AbstractActionController->onDispatch(Object(Zend\Mvc\MvcEvent)) #11 D:\softs\UwAmp\www\zf2-tutorial\ZendSkeletonApplication\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(469): call_user_func(Array, Object(Zend\Mvc\MvcEvent)) #12 D:\softs\UwAmp\www\zf2-tutorial\ZendSkeletonApplication\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(209): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure)) #13 D:\softs\UwAmp\www\zf2-tutorial\ZendSkeletonApplication\vendor\zendframework\zendframework\library\Zend\Mvc\Controller\AbstractController.php(108): Zend\EventManager\EventManager->trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure)) #14 D:\softs\UwAmp\www\zf2-tutorial\ZendSkeletonApplication\vendor\zendframework\zendframework\library\Zend\Mvc\DispatchListener.php(114): Zend\Mvc\Controller\AbstractController->dispatch(Object(Zend\Http\PhpEnvironment\Request), Object(Zend\Http\PhpEnvironment\Response)) #15 [internal function]: Zend\Mvc\DispatchListener->onDispatch(Object(Zend\Mvc\MvcEvent)) #16 D:\softs\UwAmp\www\zf2-tutorial\ZendSkeletonApplication\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(469): call_user_func(Array, Object(Zend\Mvc\MvcEvent)) #17 D:\softs\UwAmp\www\zf2-tutorial\ZendSkeletonApplication\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(209): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure)) #18 D:\softs\UwAmp\www\zf2-tutorial\ZendSkeletonApplication\vendor\zendframework\zendframework\library\Zend\Mvc\Application.php(298): Zend\EventManager\EventManager->trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure)) #19 D:\softs\UwAmp\www\zf2-tutorial\ZendSkeletonApplication\public\index.php(12): Zend\Mvc\Application->run() #20 {main}
Может ли кто-нибудь помочь мне в этом?
Вам нужно поместить свои учетные данные в локальный файл конфигурации
// config/autoload/local.php: return array( 'db' => array( 'username' => 'YOUR USERNAME HERE', 'password' => 'YOUR PASSWORD HERE', ), );
Спасибо Maks3w, я получил ту же ошибку, потому что я не создал файл local.php
для добавления кода. Я думал, что local.php.dist
работает хорошо. Все отлично после того, как у меня есть local.php
с кодом
// config / autoload / local.php:
return array( 'db' => array( 'username' => 'YOUR USERNAME HERE', 'password' => 'YOUR PASSWORD HERE', ), );
В local.php.dist
есть комментарий, который помог мне исправить это:
// Copy this file without the .dist extension at the end and populate values as needed.