haja
haja

Reputation: 1

How to call SQL Server Stored procedure in laravel?

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???

Upvotes: 0

Views: 1187

Answers (2)

kishan maharana
kishan maharana

Reputation: 222

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

Upvotes: 0

zhekaus
zhekaus

Reputation: 3194

Here is an example:

DB::statement('CALL sp_user_add(:name, :email, :password);',
                array(
                    'name' => $name,
                    'email' => $email,
                    'password' => $password
                )
            );

Upvotes: 1

Related Questions