"Access denied for user" "localhost" to database "forge" appears randomly

I have a search function for my database, but sometimes I get this message:

[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) ... 

In one of ten calls, I get this 500 error message, but I don’t know why. Other calls give the correct result.

.env

 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 

Search function:

 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); } 

database.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, ], 

I have not modified the database.php file, and all other calls work fine.

+10
php laravel
source share
3 answers

Most answers seem to be: Laravel 5.2 does not read env file

Remember to not edit your core files, as one user said. Just perform safe checks, clear the cache, work.

Hope this helps.

As a workaround, you can add your account to the DB database with all privileges.

0
source share

Try php artisan clear:cache clear the cache and reconfigure the php artisan config:cache , it might work for you.

0
source share

PLEASE EXECUTE THIS TEAM

 php artisan clear:cache 

THEN

 php artisan config:cache 
0
source share

All Articles