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 ?

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. Commented Jun 12, 2014 at 9:51
  • @KunalDethe Yes, the code is already correct as you say in application.config.php Commented Jun 12, 2014 at 10:02

2 Answers 2

3

You don't have rights to access database. Execute

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

and then

FLUSH PRIVILEGES

to get access.

Sign up to request clarification or add additional context in comments.

1 Comment

I have executed that commands from 'mysql -u root'. Great !! Now working ... thx.
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.

1 Comment

The global.php is the same, I resolved it. The problem was the rights to access the database.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.