Home > database >  Laravel stored procedure insert data to database not working
Laravel stored procedure insert data to database not working

Time:06-29

my controller

if ($request->hasFile('photo')) {
    $filenameWithExt = $request->file('photo')->getClientOriginalName();
    $filename = pathinfo($filenameWithExt, PATHINFO_FILENAME);
    $extension = $request->file('photo')->getClientOriginalExtension();
    $fileNameToStore = $filename. '_'. time().'.'.$extension;
    $request->file('photo')->storeAs('public/employee/photo', $fileNameToStore);
    $input['photo'] = $fileNameToStore;
}
         
if ($request->hasFile('resume')) {
    $filenameWithExt = $request->file('resume')->getClientOriginalName ();
    $filename = pathinfo($filenameWithExt, PATHINFO_FILENAME);
    $extension = $request->file('resume')->getClientOriginalExtension();
    $fileNameToStore = $filename. '_'. time().'.'.$extension;
    $request->file('resume')->storeAs('public/employee/resume', $fileNameToStore);
    $input['resume'] = $fileNameToStore;
}

$employee = DB::statement('call insertEmployes(?,?,?,?,?,?)', [implode(', ',$input)]);

my error

"message": "SQLSTATE[HY093]: Invalid parameter number (SQL: call insertEmployes(er, [email protected], 3, 3, Resume (1)_1656479826.png, Resume (1)_1656479826.pdf,?,?,?,?,?))", "exception": "Illuminate\\Database\\QueryException",

i am new in stored procedure in laravel.how to insert data in stored procedure

i am new in stored procedure in laravel.how to insert data in stored procedure****i am new in stored procedure in laravel.how to insert data in stored procedure

CodePudding user response:

According to your error message, the query being run from

DB::statement('call insertEmployes(?,?,?,?,?,?)', [implode(', ',$input)]);

is

call insertEmployes(er, [email protected], 3, 3, Resume (1)_1656479826.png, Resume (1)_1656479826.pdf,?,?,?,?,?)

You're only replacing 1 out of 6 ? because you're using implode.

Try

DB::statement('call insertEmployes(?,?,?,?,?,?)', $input);

or

DB::statement('call insertEmployes(?,?,?,?,?,?)', array_values($input));

CodePudding user response:

try

DB::select('exec my_stored_procedure("$Param1", "$param2",..)');

or

DB::select('exec my_stored_procedure(?,?,..)',array($Param1,$param2));
  • Related