Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

GGS's avatar
Level 1

Laravel illuminate database queryexception

I have a problem to insert into database I used WAMP server and used Laravel.

The problem is I have 4 images and other data in my form I want to import them all to the database when I try to import 3 images the insert works and when I want to insert 4 I faced this error Illuminate\Database\QueryException.

I tried to modify php ini but not work thats my Controller

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\game;
use Illuminate\Support\Facades\Auth;

class GameController extends Controller
{ 
    public function store(Request $request)
    {        
        $lastGame = Game::latest()->first();
        $newIDG = $lastGame ? $lastGame->IDG + 1 : 1;
    
        $request->merge(['IDG' => $newIDG]);

        $request->validate([
            "title"         => ['required', 'string', 'unique:games'],
            "description"   => ['required', 'string'],
            "main_picture"  => ['required', 'image', 'mimes:jpeg,png,jpg'],
            'jeux_prix'     => ['required', 'numeric', 'min:20'], // Fixed validation rule syntax
            "category".     => ['required', 'string'],
            "download_path" => ['required', 'string'],
        ]);

        $imagePath = $request->main_picture->getPathname(); // Get the temporary path of the uploaded file
        $imageData = file_get_contents($imagePath); // Read the contents of the uploaded file        
    
        // Store the screenshots
        if (!is_array($request->file('screenshots')) ||count($request->file('screenshots')) !== 3) {
            return redirect()->back()->withErrors(['screenshots' => 'You Must Import 3 Screens']);
        }

        foreach ($request->file('screenshots') as $screenshot) {
            $imagePath = $screenshot->getPathname(); // Get the temporary path of the uploaded file
            $imageData = file_get_contents($imagePath); // Read the contents of the uploaded file
            $imageDataArray[] = $imageData; // Add the image data to the array
        }

        $data = $request->except(['main_picture', 'screenshots']);
    
        $data['etat_jeux'] = "inactif";
        $data['Screen1'] = $imageDataArray[0];
        $data['Screen2'] = $imageDataArray[1];
        $data['Screen3'] = $imageDataArray[2];
        $data['Main_picture'] = $imageData;
        $data['id'] = Auth::guard('creator')->id();
      
        game::create($data);

        return redirect()->route('creator.dashboard.home')->with('success', 'Game Added successfully!');        
    }
}

and thats my migration

public function up(): void
    {
        Schema::create('games', function (Blueprint $table) {
            $table->bigInteger('IDG')->primary();

            $table->string('Title')->unique();
            $table->string('Description')->nullable();
            $table->string('Category')->nullable();
            $table->integer('Jeux_Prix')->nullable();
            $table->date('date_publishing')->nullable();
            $table->longText('Main_Picture')->charset('binary')->nullable(); // LONGBLOB
            $table->longText('Screen1')->charset('binary')->nullable(); // LONGBLOB
            $table->longText('Screen2')->charset('binary')->nullable(); // LONGBLOB
            $table->longText('Screen3')->charset('binary')->nullable(); // LONGBLOB
            $table->string('Download_Path')->nullable();
            $table->string('etat_jeux')->nullable();
            $table->string('ECIN', 20)->nullable();
            $table->BigInteger('id')->nullable();
            $table->BigInteger('ID_Pack')->nullable();
            $table->foreign('id')->references('id')->on('creators')->onDelete('cascade');
            // $table->foreign('ID_Pack')->references('id')->on('packs')->onDelete('cascade');
            $table->timestamps();
        });
    }
0 likes
5 replies
JussiMannisto's avatar

I faced this error Illuminate\Database\QueryException

That's just the type of the exception. What does the error message say?

1 like
GGS's avatar
Level 1

I USE TRY CATCH AND I SAW THAT THE CONNECTION WITH THE SERVER SHUTDOWN WHEN I TRY TO SUBMIT THE DATA TO DATABASE

GGS's avatar
Level 1

THE ERROR I GO IN THE LOG local.ERROR: Exception occurred: SQLSTATE[HY000]: General error: 2006 MySQL server has gone away (Connection: mysql, SQL: insert into games (title, description, jeux_prix, category, download_path, IDG, etat_jeux, Screen1, Screen2, Screen3, Main_picture, id, updated_at, created_at) values (Hamid, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, 123, Action, web3.game.top, 2, inactif, ����

gych's avatar

@GGS Might be possible that your INSERT is taking longer than the configured timeout for your database. Is there any specific reason why you want to store the images in your database and not in file storage?

1 like
GGS's avatar
Level 1

Thanks all i solve the problem by execute this in mysql set global interactive_timeout = 28800;

SET @@LOCAL.wait_timeout=300;

Please or to participate in this conversation.