0
votes

I have a problem regarding zend framework. I have the source file for a website that is developed using php & zend framework & MySQL. This website is developed by other people previously. I want to run this files locally on my computer so that i can make changes for the website. I have xampp and php installed but when I try to run it, an error come out on the browser:

Fatal error: Uncaught exception 'Zend_Db_Adapter_Exception' with message 'SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES)' in C:\xampp\htdocs\www\medicatoz\library\Zend\Db\Adapter\Pdo\Abstract.php:143 
Stack trace: 
#0 C:\xampp\htdocs\www\medicatoz\library\Zend\Db\Adapter\Abstract.php(441): Zend_Db_Adapter_Pdo_Abstract->_connect()
#1 C:\xampp\htdocs\www\medicatoz\library\Zend\Db\Adapter\Pdo\Abstract.php(230): Zend_Db_Adapter_Abstract->query('SET NAMES UTF8', Array)
#2 C:\xampp\htdocs\www\medicatoz\conf\bootstrap.php(63): Zend_Db_Adapter_Pdo_Abstract->query('SET NAMES UTF8') #3 C:\xampp\htdocs\www\medicatoz\index.php(4): require('C:\xampp\htdocs...') #4 {main} thrown in C:\xampp\htdocs\www\medicatoz\library\Zend\Db\Adapter\Pdo\Abstract.php on line 143

Can you guys help me figure out what is this error about? I suspect it might be the db but i don't know the specific. I was hoping maybe someone that have encountered this error before could give me an idea. Thanks in advance.

Hi guys, I've tried your suggestion and it seems i've passed the db part. but now it display this error :

Array ( [0] => Zend_Controller_Dispatcher_Exception Object ( [message:protected] => Invalid controller specified (www) [string:Exception:private] => [code:protected] => 0 [file:protected] => C:\xampp\htdocs\www\library\Zend\Controller\Dispatcher\Standard.php [line:protected] => 241 [trace:Exception:private] => Array ( [0] => Array ( [file] => C:\xampp\htdocs\www\library\Zend\Controller\Front.php [line] => 936 [function] => dispatch [class] => Zend_Controller_Dispatcher_Standard [type] => -> [args] => Array ( [0] => Zend_Controller_Request_Http Object ( [_paramSources:protected] => Array ( [0] => _GET [1] => _POST ) [_requestUri:protected] => /www/web/themes/medicatoz/index.phtml [_baseUrl:protected] => [_basePath:protected] => [_pathInfo:protected] => /www/web/themes/medicatoz/index.phtml [_params:protected] => Array ( [controller] => www [action] => web [themes] => medicatoz [module] => default ) [_aliases:protected] => Array ( ) [_dispatched:protected] => 1 [_module:protected] => default [_moduleKey:protected] => module [_controller:protected] => www [_controllerKey:protected] => controller [_action:protected] => web [_actionKey:protected] => action ) [1] => Zend_Controller_Response_Http Object ( [_body:protected] => Array ( ) [_exceptions:protected] => Array RECURSION [_headers:protected] => Array ( ) [_headersRaw:protected] => Array ( ) [_httpResponseCode:protected] => 200 [_isRedirect:protected] => [_renderExceptions:protected] => [headersSentThrowsException] => 1 ) ) ) [1] => Array ( [file] => C:\xampp\htdocs\www\index.php [line] => 5 [function] => dispatch [class] => Zend_Controller_Front [type] => -> [args] => Array ( ) ) ) [previous:Exception:private] => ) )

I think this shows that there is some limitation to the access that preventing it from displaying the proper website. Any idea how to overcome this? Thanks for your patience and help.

2
Access denied for user 'root'@'localhost' is the root of the problem. Do you have a database set up? Is it configured properly?Pekka
Have you tried logginto mysql with the username and password hyou have provided in the file. mysql -u root -p and type the password. Also try logging in without a password. This is most probably a password issueSoWhat
@Pekka root'@'localhost' is the root of the problem. Pun Intended ;)?SoWhat
@Somesh lol, not really :)Pekka

2 Answers

1
votes

Put Your code on folder config/autoload

create two file name local.php put this code

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

another file database.local.php post this code

<?php

return array(
   'db' => array(
      'driver'         => 'Pdo',
      'dsn'            => 'mysql:dbname=testdb;host=localhost',
   ),
   'service_manager' => array(
      'factories' => array(
         'Zend\Db\Adapter\Adapter' => 'Zend\Db\Adapter\AdapterServiceFactory',
      ),
   ),
);
0
votes

Check to make sure you've access to your database, get the database name, username and password to access db and change the code as follows

If you're using Zend Framework 1.x.x
goto PROJECT_DIR/application/config/application.ini

resources.db.adapter = "pdo_mysql"
resources.db.params.host = "localhost"
resources.db.params.username = "DB_USERNAME"
resources.db.params.password = "DB_PASSWORD"
resources.db.params.dbname = "DB_NAME"
resources.db.idDefaultTableAdapter = true

And if Zend Framework 2.x.x
goto PROJECT_DIR/config/autoload/global.php and you could also check local.php in autoload folder

return array(
   'db' => array(
       'driver' => 'Pdo',
       'dsn' => 'mysql:dbname=DB_NAME;host=localhost',
       'username' => 'DB_USERNAME',
       'password' => 'DB_PASSWORD',
       'driver_options' => array(
           PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\''
       ),
   ),
   ....
);