Connector.php 第 55 行中的 Laravel PDOException 错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34740908/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 13:02:09  来源:igfitidea点击:

Laravel PDOException error in Connector.php line 55

phphtmlmysqllaravellaravel-5

提问by Chonchol Mahmud

I am beginner in Laravel PHP framework.That's why i am trying basic task from HERE (Laravel.com).I followed this basic task step by step.But after finishing this i am getting an error.I am putting the errorhere.

我是Laravel PHP 框架的初学者。这就是为什么我要尝试从HERE (Laravel.com)开始的基本任务。我一步一步地遵循了这个基本任务。但是在完成这个之后我收到了一个错误。我把错误放在这里。

PDOException in C:\xampp\htdocs\quickstart\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'homestead'@'localhost' (using password: YES)

PDOException in C:\xampp\htdocs\quickstart\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'homestead'@'localhost' (使用密码:是)

What is the meaning of this error?

这个错误是什么意思?

SQLSTATE[HY000] [1045] Access denied for user 'homestead'@'localhost' (using password: YES)

SQLSTATE[HY000] [1045] 用户 'homestead'@'localhost' 访问被拒绝(使用密码:YES)

Here is my .envfile.

这是我的.env文件。

DB_HOST=localhost
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=

I have found similar problem in here. But there is no proper solution of it.

我在这里发现了类似的问题。但没有适当的解决方案。

Here i add few lines (48 to 63)from Connector.php.

在这里,我从Connector.php添加了几行(48 到 63)

public function createConnection($dsn, array $config, array $options)
{
    $username = Arr::get($config, 'username');

    $password = Arr::get($config, 'password');

    try {
        $pdo = new PDO($dsn, $username, $password, $options);
    } catch (Exception $e) {
        $pdo = $this->tryAgainIfCausedByLostConnection(
            $e, $dsn, $username, $password, $options
        );
    }

    return $pdo;
}

Really i do get right solution of it.Have anyone who can give me the right solution of it? BTW this is laravel 5.2.

我真的得到了正确的解决方案。有没有人可以给我正确的解决方案?顺便说一句,这是laravel 5.2。

Thanks in advanced.

提前致谢。

采纳答案by Rai

SQLSTATE[HY000] [1045] Access denied for user 'homestead'@'localhost' (using password: YES)

SQLSTATE[HY000] [1045] 用户 'homestead'@'localhost' 访问被拒绝(使用密码:YES)

This means, that your provided username and password is incorrect. If you're using homestead, default username ir homesteadand the password is secret. Also, You might need to change the database port, since the default laravel configuration will look for port 3306, but homestead runs on port 33060

这意味着,您提供的用户名和密码不正确。如果你使用 homestead,默认用户名 irhomestead和密码是secret. 此外,您可能需要更改数据库端口,因为默认的 Laravel 配置将查找 port 3306,但 homestead 在端口上运行33060

So the .envfile should look like this:

所以.env文件应该是这样的:

DB_HOST=127.0.0.1
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
DB_PORT=33060

Source

来源

回答by Ahmed Al Bermawy

You need to install php module for pdo_mysql

您需要为pdo_mysql安装 php 模块

to do that run this command on your server

为此,请在您的服务器上运行此命令

yum install php-mysqlnd

yum install php-mysqlnd

Then restart httpd service

然后重启httpd服务

service httpd restart

service httpd restart