Ad

How To Fix 'Incorrect Syntax Near '@P1'.' Error In Laravel

While trying to call a stored procedure function in Laravel, I keep getting this error

SQLSTATE[42000]: [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Incorrect syntax near '@P1'. (SQL: exec TestProcedure(울산광역시, 남구, 신정동))

Note that in SSMS this stored procedure works fine when I pass the variables, which are, city, county, and address.

Here is my code in Laravel;

public function filterKoreanAddress(Request $request)
{
    $data = $request->all();
    $results = DB::select(
        'exec TestProcedure(?, ?, ?)',
        [
            $request->input('city'),
            $request->input('county'),
            $request->input('address'),
        ]
    );
    dd($results);
}

So, did I do anything wrong in the code?

Ad

Answer

try it like this

$results = DB::select(
    'exec TestProcedure(?, ?, ?)',
    array(
        $request->input('city'),
        $request->input('county'),
        $request->input('address'),
    )
);
Ad
source: stackoverflow.com
Ad