使用 PHP 中的参数调用 SQL Server 存储过程 [英] Call a SQL Server stored proc with parameters in PHP

查看:63
本文介绍了使用 PHP 中的参数调用 SQL Server 存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基于此:

如何在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

这篇关于使用 PHP 中的参数调用 SQL Server 存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆