Zend错误SQLSTATE [HY000] [1045]

时间:2013-02-05 05:54:24

标签: zend-framework zend-db

我遇到了zend框架和与数据库连接的问题,我正在尝试创建一个登录,创建表,代码显然很好,但是给了我这个:

An error occurred
Application error
Exception information:

Message: SQLSTATE[HY000] [1045] Access denied for user 'onetag51_teste'@'localhost' (using  password: YES)
Stack trace:

#0 C:\xampp\Zend\library\Zend\Db\Adapter\Pdo\Mysql.php(109):   Zend_Db_Adapter_Pdo_Abstract->_connect()
#1 C:\xampp\Zend\library\Zend\Db\Adapter\Abstract.php(860): Zend_Db_Adapter_Pdo_Mysql->_connect()
#2 C:\xampp\Zend\library\Zend\Db\Adapter\Abstract.php(930): Zend_Db_Adapter_Abstract->quote('pass1', NULL)
#3 C:\xampp\Zend\library\Zend\Auth\Adapter\DbTable.php(449): Zend_Db_Adapter_Abstract->quoteInto('`password` = ?', 'pass1')
#4 C:\xampp\Zend\library\Zend\Auth\Adapter\DbTable.php(368): Zend_Auth_Adapter_DbTable->_authenticateCreateSelect()
#5 C:\xampp\Zend\library\Zend\Auth.php(117): Zend_Auth_Adapter_DbTable->authenticate()
#6 C:\xampp\htdocs\Eulen\application\controllers\AuthenticationController.php(27): Zend_Auth->authenticate(Object(Zend_Auth_Adapter_DbTable))
#7 C:\xampp\Zend\library\Zend\Controller\Action.php(516): AuthenticationController->logininAction()
#8 C:\xampp\Zend\library\Zend\Controller\Dispatcher\Standard.php(308): Zend_Controller_Action->dispatch('logininAction')
#9 C:\xampp\Zend\library\Zend\Controller\Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#10 C:\xampp\Zend\library\Zend\Application\Bootstrap\Bootstrap.php(97): Zend_Controller_Front->dispatch()
#11 C:\xampp\Zend\library\Zend\Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#12 C:\xampp\htdocs\Eulen\public\index.php(26): Zend_Application->run()
#13 {main}  

Request Parameters:

array (
'controller' => 'authentication',
'action' => 'loginin',
'module' => 'default',
 )  

我正在寻找一个解决方案,一些可能的错误,拼写错误(我没有发现任何),无法使用我的传递和用户连接到phpmyadmin(如果我去phpmyadmim网站,我可以使用用户名和密码输入。)

我尝试了几种解决方案,但我无法弄明白。

我错过了什么。

file config.ini:

 resources.db.params.charset = "utf8"
 resources.db.adapter = "pdo_mysql"
resources.db.params.host = localhost
resources.db.params.username = "onetag51_teste"
resources.db.params.password = "*******"
resources.db.params.dbname = "onetag51_eulenhugo"

最好放在身份验证控制器上,也许问题就在那里..

 <?php

 class AuthenticationController extends Zend_Controller_Action
{

 public function init()
 {
    /* Initialize action controller here */
}

public function indexAction()
{
    // action body
}

public function logininAction()
{
    // action body
    $authAdapter =$this->getAuthAdapter();
    $username='hugo';
    $password='pass1';

    $authAdapter->setIdentity($username)
                ->setCredential($password);

    $auth =Zend_Auth::getInstance();
    $result = $auth->authenticate($authAdapter);
    if($result->isValid())
    {
        echo 'valid';
    }
    else
    {
        echo 'invalid';
    }
}

public function logoutAction()
{
    // action body
}
private function  getAuthAdapter()
{
    $authAdapter = new Zend_Auth_Adapter_DbTable(Zend_Db_Table::getDefaultAdapter());
    $authAdapter->setTableName('users')
                ->setIdentityColumn('username')
                ->setCredentialColumn('password');

    return $authAdapter;
}              


}

我一直在跟我的一个朋友说话,他告诉我,我需要通过zend设置对phpmyadmim acesse的许可......

我该怎么做?

2 个答案:

答案 0 :(得分:0)

您不需要在配置文件中使用adpater,用户名,密码和dbname周围的引号。我不在我的手中,希望这会有所帮助。

我发现了一些可能有用的阅读access denied for user @ 'localhost' to database '',因为它提到了

  

如果您希望外部访问数据库(即网页),则需要向用户授予权限。    在答案中。

There is also this link about adding the users to the database in mysql.

希望这有帮助

答案 1 :(得分:0)

所以问题与priveleges有关,感谢ARJMP,我试过改变了priveleges但是主机让我这么做,所以我做的是使用xamp创建一个本地数据库并尝试使用数据库登录在xamp中创建,它有效...