0

Based on this :

how to execute sql server stored procedure on php?

Tried the following :

$odbc = odbc_connect($DB1_ODBC,$DB1_USER,$DB1_PWD);  // proven to be fully functionnal
$result = odbc_exec($odbc,"CALL importClient( @name = 'hello',@number = 457)"); 

It does not call the stored procedure, i can't see any error code.

I replaced "CALL by "EXEC but it's not working in either cases.

Otherwise, the stored procedure can be run by using the same credentials to connect to the database, and using this SQL statement :

EXECUTE [dbo].[importClient] @name = 'hello',@number = 457

I couldn't find anything helpful, neither think of another way, and I definitely need the parameters.

Antoine Pelletier
  • 3,164
  • 3
  • 40
  • 62

2 Answers2

1
$stmt = odbc_prepare($odbc, "call dbo.importClient(?, ?)");
odbc_execute($stmt, ["hello", 457]);

Using a prepared statement will protect your code from SQL injection attacks. Use this when you replace your literal values with variables containing user input.

Joshua Jones
  • 1,364
  • 1
  • 9
  • 15
0

It finally worked with :

$result = odbc_exec($odbc,"EXECUTE importClient @name = 'hello', @number = 457");

But this isn't protected against SQL injections, so it might not be the best answer

Antoine Pelletier
  • 3,164
  • 3
  • 40
  • 62