dimanche 29 janvier 2017

Laravel 5.2 - Calling stored procedure with error [SQL Server] Incorrect syntax near '@P1'

I'm using Laravel 5.2 and PHP PDO for connect Mssql database. I created stored procedure like this:

GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description:  <Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[TestSelect](
@policy nvarchar,
@memberval int output
)
AS
BEGIN
select * from Member
set @memberval=(select count(*) from Member where (PolicyNo LIKE '%' + @policy + '%'))
END

I have write php source in Laravel 5.2 like this:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;

class ExtractController extends Controller
{
    public function index()
    {

    $policy = '00006001';
    $test = \DB::connection('sqlsrv')->select('EXEC TestSelect(?)',array($policy));

    return view('extract.index');


    }//
}

I got this error every time:

QueryException in Connection.php line 729: SQLSTATE[42000]: [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Incorrect syntax near '@P1'. (SQL: EXEC TestSelect(00006001))

Do you have any idea for this error?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2kIWvB4
via IFTTT

Aucun commentaire:

Enregistrer un commentaire