gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 23:39:39 25 4
gpt4 key购买 nike

我是 Laravel PHP 框架的初学者。这就是为什么我正在尝试来自 HERE (Laravel.com) 的基本任务。 .我一步一步地完成了这个基本任务。但是在完成这个之后我得到了一个错误。我将错误放在这里。

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

这个错误是什么意思?

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

这是我的.env 文件。

DB_HOST=localhost
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=

我在 here 中发现了类似的问题.但目前还没有合适的解决办法。

这里我从 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;
}

我确实找到了正确的解决方案。谁能给我正确的解决方案?顺便说一句,这是 laravel 5.2。

最佳答案

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

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

上运行

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

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

Source

关于php - Connector.php 第 55 行中的 Laravel PDOException 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34740908/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com