gpt4 book ai didi

php - "Access denied for user ' '@' localhost ' to database ' forge”随机出现

转载 作者:可可西里 更新时间:2023-10-31 22:52:09 27 4
gpt4 key购买 nike

我的数据库有搜索功能,但有时我会收到此消息:

[2016-02-04 07:03:18] local.ERROR: PDOException: SQLSTATE[HY000] [1044] Access denied for user ''@'localhost' to database 'forge' in C:\xampp\htdocs\reko\api\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:55
Stack trace:
#0 C:\xampp\htdocs\reko\api\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php(55): PDO->__construct('mysql:host=loca...', 'forge', '', Array)
...

在十个调用中的一个中,我收到了这个 500 错误消息,但我不知道为什么。其他调用给出了正确的结果。

.环境

APP_ENV=local
APP_DEBUG=true
APP_KEY=bJM6O0MnrIPaTNwKKOqNJkGinRDv1fnc

DB_HOST=localhost
DB_DATABASE=reko
DB_USERNAME=root
DB_PASSWORD=

CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

搜索功能:

public function search(Modul $modul, Request $request)
{
$question = Question::whereModulId($modul->id)
->where('value', 'LIKE', '%' . $request->get('keywords') . '%')
->with('tags')
->whereHas('exams', function ($query) use ($request) {
$query->where('date', '>=', $request->get('year').'-01-01');
});
if (!$request->get('parent'))
$question->where('type', '<>', 'parent');
if (!$request->get('own'))
$question->where('type', '<>', 'own');
if (!$request->get('normal'))
$question->where('type', '<>', 'normal');
if ($request->get('answered'))
$question->has('answers');
return $question->paginate(10);
}

数据库.php

'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],

我没有修改 database.php 文件,所有其他调用都运行良好。

最佳答案

请运行此命令

php artisan cache:clear 

然后

php artisan config:cache

关于php - "Access denied for user ' '@' localhost ' to database ' forge”随机出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35187814/

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