1

I'm following the user guide tutorial directly from the Zend framewrok website; I create the module ALbum and the mysql table as the guide says, but when I open the link 'localhost:8080/album' return a page error with the message below :

Connect Error: SQLSTATE[42000] [1044] Access denied for user ''@'localhost' to database 'zf2tutorial'

I have also configurated the global.php and local.php as the guide says, in particular I have filled in the local.php this credential :

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

because the 'zf2tutotial' database was inserted with the root user without password. Why the framework doesn't access the database ?

edigu
  • 9,878
  • 5
  • 57
  • 80
Davide
  • 113
  • 2
  • 11
  • Please check in `application.config.php` that you have written - `'config/autoload/{,*.}{global,local}.php',` The `db` array from `local.php` needs to be merged with the array from `global.php`. – Kunal Dethe Jun 12 '14 at 09:51
  • @KunalDethe Yes, the code is already correct as you say in application.config.php – Davide Jun 12 '14 at 10:02

2 Answers2

3

You don't have rights to access database. Execute

GRANT ALL PRIVILEGES ON *.* TO ''@localhost

and then

FLUSH PRIVILEGES

to get access.

onedevteam.com
  • 3,838
  • 10
  • 41
  • 74
0

Please check your global.php file, and match code with the following

 return array(
 'db' => array(
     'driver'         => 'Pdo',
     'dsn'            => 'mysql:dbname=zf2tutorial;host=localhost',
     'driver_options' => array(
         PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\''
     ),
 ),
 'service_manager' => array(
     'factories' => array(
         'Zend\Db\Adapter\Adapter'
                 => 'Zend\Db\Adapter\AdapterServiceFactory',
     ),
 ),

);

and your local.php is correct.

  • The **global.php** is the same, I resolved it. The problem was the rights to access the database. – Davide Jun 12 '14 at 10:05