使用 PHP 中的参数调用 SQL Server 存储过程
问题描述:
基于此:
尝试了以下方法:
$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.
我将 "CALL
替换为 "EXEC
但它在任何一种情况下都不起作用.
I replaced "CALL
by "EXEC
but it's not working in either cases.
否则,可以使用相同的凭据连接到数据库,并使用此 SQL 语句来运行存储过程:
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.
答
终于成功了:
$result = odbc_exec($odbc,"EXECUTE importClient @name = 'hello', @number = 457");
但这不能防止 SQL 注入,因此它可能不是最佳答案
But this isn't protected against SQL injections, so it might not be the best answer