0

My stored procedure : setUsers

BEGIN
    INSERT INTO tblusers (email,password) values (email,password);
    SET id =  LAST_INSERT_ID();
END

My laravel code:

 DB::insert('call tblusers (?,?,@id)',array($req->email,Hash::make(($req->password))))

Here I have tried with lastInsertId(); and insertGetId(); but it always returns a boolean.

Moksh
  • 3
  • 4
  • Will https://stackoverflow.com/questions/26760414/mysql-stored-procedure-return-value help? Otherwise, please add the complete definition of your stored procedure – Nico Haase Jun 05 '18 at 08:34
  • Actually when I use my mentioned stored procedure in phpmyadmin and insert data using it, it returns an inserted id as 'id' column. But I want to handle it via laravel code mean when I use this code how I can save last inserted id in variable? – Moksh Jun 05 '18 at 08:53
  • Can you share the **exact** definition of your stored procedure? – Nico Haase Jun 05 '18 at 08:54
  • Probably, https://stackoverflow.com/questions/42737433/get-result-of-stored-procedure-laravel will help? – Nico Haase Jun 05 '18 at 08:55
  • I have just written BEGIN INSERT INTO tblusers (email,password) values (email,password); SET id = LAST_INSERT_ID(); END and in laravel code I have just written $myid = DB::insert('call tblusers (?,?,@id)',array($req->email,Hash::make(($req->password)))) but here I am getting boolean in $myid instead of inserted id – Moksh Jun 05 '18 at 08:59
  • And your definition has no parts defining the name and input variables? – Nico Haase Jun 05 '18 at 09:00
  • it has id, email and password in table – Moksh Jun 05 '18 at 09:02
  • Have you tried something else than `DB::insert`? You are not actually inserting anything, but calling that stored procedure. And it does nothing more than returning the ID? That's something each ORM can handle on its own, without using SP – Nico Haase Jun 05 '18 at 09:08
  • Yes I have tried with DB::insert, DB::statements and DB::raw also. It inserts with the help of stored procedure call but it should return and id but it always returns bool(true) – Moksh Jun 05 '18 at 09:10
  • 1
    And why do you need to use a stored procedure after all? – Nico Haase Jun 05 '18 at 09:12
  • Actually its my project's requirement to use stored procedure otherwise insertGetId(); works find with laravel code. – Moksh Jun 05 '18 at 09:16
  • https://stackoverflow.com/questions/42737433/get-result-of-stored-procedure-laravel link is helpful but its for select not an insert. – Moksh Jun 05 '18 at 09:16
  • If I run stored procedure in phpmyadmin, it works perfectly and returns inserted id. But I do not know how to store this inserted id with laravel code? Could anyone help please? – Moksh Jun 08 '18 at 05:53

0 Answers0