Question

In the documentation for calling a SQL Server stored procedure with parameters from PHP using the sqlsrv extension, it uses a bizarre syntax:

{call SubtractVacationHours( ?, ?)}

What I would expect would be:

EXEC SubtractVacationHours ?, ?;

In the SQL Server documentation for executing a T-SQL stored procedure it only allows EXEC | EXECUTE as the command words. So I would have thought the query would cause an error.

You can certainly call sqlsrv_query with SQL of EXEC SubtractVacationHours with specified parameters (i.e. with the question marks replaced with values).

After some further research on Parameterised queries, it seems that the 'CALL' comes from having to call it through an ODBC provider.

So will the second EXEC syntax actually work? Or do parameterized stored procedure calls through the sqlsrv driver have to use the ODBC CALL syntax?

Was it helpful?

Solution

I have tested with my code and both forms of the syntax work. According to this IIS blog post on Breaking API changes in the February '08, it is recommended to use the CALL syntax though:

We can now call that stored procedure using the canonical-call syntax, recommended for stored procedures using the SQL Server 2005 Driver for PHP:

$sql = '{? = CALL CreateProduct (?, ?, ?, ?)}';
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top