title: Zend 2 Cannot connect to Database
body: <p>I am using wamp server with MySQL for writing my first zend 2 application.</p>
  
  <p>I have the following problem:</p>
  
  <pre><code>Message:
  Connect Error: SQLSTATE[HY000] [1044] Access denied for user ''@'localhost' to database 'kljpeer'
  Stack trace:
  #0 D:\Git\klj-website\vendor\zendframework\zendframework\library\Zend\Db\Adapter\Driver\Pdo\Pdo.php(249): Zend\Db\Adapter\Driver\Pdo\Connection-&gt;connect()
  #1 D:\Git\klj-website\vendor\zendframework\zendframework\library\Zend\Db\Sql\Sql.php(120): Zend\Db\Adapter\Driver\Pdo\Pdo-&gt;createStatement()
  #2 D:\Git\klj-website\vendor\zendframework\zendframework\library\Zend\Db\TableGateway\AbstractTableGateway.php(232): Zend\Db\Sql\Sql-&gt;prepareStatementForSqlObject(Object(Zend\Db\Sql\Select))
  #3 D:\Git\klj-website\vendor\zendframework\zendframework\library\Zend\Db\TableGateway\AbstractTableGateway.php(208): Zend\Db\TableGateway\AbstractTableGateway-&gt;executeSelect(Object(Zend\Db\Sql\Select))
  #4 D:\Git\klj-website\vendor\zendframework\zendframework\library\Zend\Db\TableGateway\AbstractTableGateway.php(195): Zend\Db\TableGateway\AbstractTableGateway-&gt;selectWith(Object(Zend\Db\Sql\Select))
  #5 D:\Git\klj-website\module\Website\src\Website\Model\PostTable.php(24): Zend\Db\TableGateway\AbstractTableGateway-&gt;select()
  #6 D:\Git\klj-website\module\Website\src\Website\Controller\HomeController.php(23): Website\Model\PostTable-&gt;fetchAll()
  #7 D:\Git\klj-website\vendor\zendframework\zendframework\library\Zend\Mvc\Controller\AbstractActionController.php(83): Website\Controller\HomeController-&gt;indexAction()
  #8 [internal function]: Zend\Mvc\Controller\AbstractActionController-&gt;onDispatch(Object(Zend\Mvc\MvcEvent))
  #9 D:\Git\klj-website\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(468): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
  #10 D:\Git\klj-website\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(207): Zend\EventManager\EventManager-&gt;triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
  #11 D:\Git\klj-website\vendor\zendframework\zendframework\library\Zend\Mvc\Controller\AbstractController.php(117): Zend\EventManager\EventManager-&gt;trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
  #12 D:\Git\klj-website\vendor\zendframework\zendframework\library\Zend\Mvc\DispatchListener.php(114): Zend\Mvc\Controller\AbstractController-&gt;dispatch(Object(Zend\Http\PhpEnvironment\Request), Object(Zend\Http\PhpEnvironment\Response))
  #13 [internal function]: Zend\Mvc\DispatchListener-&gt;onDispatch(Object(Zend\Mvc\MvcEvent))
  #14 D:\Git\klj-website\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(468): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
  #15 D:\Git\klj-website\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(207): Zend\EventManager\EventManager-&gt;triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
  #16 D:\Git\klj-website\vendor\zendframework\zendframework\library\Zend\Mvc\Application.php(313): Zend\EventManager\EventManager-&gt;trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
  #17 D:\Git\klj-website\public\index.php(17): Zend\Mvc\Application-&gt;run()
  #18 {main}
  </code></pre>
  
  <p>This is my config file: global.php</p>
  
  <pre><code>return array(
      'db' =&gt; array(
           'driver'         =&gt; 'Pdo',
           'dsn'            =&gt; 'mysql:dbname=kljpeer;host=localhost',
           'driver_options' =&gt; array(
               PDO::MYSQL_ATTR_INIT_COMMAND =&gt; 'SET NAMES \'UTF8\''
           ),
       ),
       'service_manager' =&gt; array(
           'factories' =&gt; array(
               'Zend\Db\Adapter\Adapter'
                       =&gt; 'Zend\Db\Adapter\AdapterServiceFactory',
           ),
       ),
  );
  </code></pre>
  
  <p>This is my config file: local.php.dist</p>
  
  <pre><code>return array(
       'db' =&gt; array(
           'username' =&gt; 'root',
           'password' =&gt; '',
       ),
  );
  </code></pre>