0

How to call SQL Server Stored procedure in Laravel?

Hi,

I can't call SQL Server Stored Procedure from Laravel. Coming errors.

Please help me anyone???

2
  • 2
    Which Laravel version? What have you tried? What's the error message? Show some code. Commented Aug 6, 2013 at 7:00
  • Actually, DB::connection('mysql')->query('select * from metadata'); - is getting data. MySQL Stored Procedure : CREATE PROCEDURE GetAllProducts() SELECT * FROM users_metadata; But, DB::connection('mysql')->query('CALL GetAllProducts()'); - is getting Boolean value 1 only. Commented Aug 6, 2013 at 7:44

2 Answers 2

1

Here is an example:

DB::statement('CALL sp_user_add(:name, :email, :password);',
                array(
                    'name' => $name,
                    'email' => $email,
                    'password' => $password
                )
            );
Sign up to request clarification or add additional context in comments.

Comments

0

You can easily call stored procedure in laravel in two ways

  • using parameter
  • without using parameter

Without Using parameter

class CheckController extends Controller
{
    public function callProcedure()
    {
     // Calling Stored Procedure from MySQL
     $alluser = DB::select('call getalluser()'); 
     return $alluser;
    }
}

Using parameter

class CheckController extends Controller
{
    public function callProcedure($id)
    {
     // Calling Stored Procedure from MySQL
     $specificuser = DB::select('call getspecificuser(?)',array($id));
     return $specificuser;
    }
}

You can refer the following article for better understanding How to call stored procedure in laravel

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.