0
votes

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 ?

2
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
@KunalDethe Yes, the code is already correct as you say in application.config.phpDavide

2 Answers

3
votes

You don't have rights to access database. Execute

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

and then

FLUSH PRIVILEGES

to get access.

0
votes

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.