1

When i write some data trough laravel/lumen code to mysql it works most of the time but randomly fails with:

SQLSTATE[HY000] [1044] Access denied for user ''@'localhost' to database 'forge'

Code:

for($items as $item) {
    $ItemCollection = ItemCollection::where([
        ['id', '=', $ItemCollectionId],
        ['finished', '=', 0],
    ])->first();

    $Item = new Item(['item_id' => $item->id]);
    $ItemCollection->items()->save($item);

    if ($ItemCollection->items()->count() === $ItemCollection->itemCount) {
        $ItemCollection->finished = 1;
        $ItemCollection->save();
    }
}

My .env looks like this:

APP_ENV=local
APP_DEBUG=true
APP_KEY=
APP_TIMEZONE=UTC

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=

CACHE_DRIVER=memcached
QUEUE_DRIVER=sync

Does anyone have a idea where it is going wrong?

  • 2
    `write some data to mysql` means ? directly from phpmyadmin ? or by laravel code you inserted some data and then you are getting this error ? – Niklesh Raut Nov 17 '16 at 12:35
  • http://stackoverflow.com/questions/29986626/pdoexception-1044-sqlstatehy000-1044-access-denied-for-user-localhost – Blinkydamo Nov 17 '16 at 12:36
  • It means trough laravel/lumen code. When i insert data via a loop i randomly get this error. @Rishi – Octavia Kitsune Nov 17 '16 at 15:51
  • @Blinkydamo The error that occurs in the link you posted is different from mine. Inserting works but randomly fails, it is not working never. I also allready use .env. – Octavia Kitsune Nov 17 '16 at 15:56

0 Answers0