使用SQLSRV调用存储过程 [英] Calling a stored procedure with SQLSRV

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

问题描述

所以我有一个我想调用的存储过程,它将一个参数作为整数并返回10个公司。这里是MSSQL中的SP http://pastebin.com/shhakP81

So I have a stored procedure I'd like to call, it takes one argument as an integer and returns 10 companies. Here's the SP inside MSSQL http://pastebin.com/shhakP81

这是我的sql语句

$companiesSQL = "{call WEBgetCompanylistByIndIDTen( ? )}";

参数

$params = array(array($industryID, SQLSRV_PARAM_IN));

查询

$companiesStmt = sqlsrv_query($companiesHandle, $companiesSQL, $params);

并尝试打印出结果会给我一个错误,说明

and trying to print out the results gets me an error stating that


sqlsrv_fetch_object()期望参数1为资源,布尔值为

我知道 $ companiesStmt 应该是一个语句资源,但它是一个布尔值,这意味着查询失败。

I know that $companiesStmt SHOULD be a statement resource, but it's a boolean, which means that the query failed.

while($row = sqlsrv_fetch_object($companiesStmt))
{
    echo $row->COM."<br />";
}

我知道连接有效,因为我可以调用不同的存储过程在该表中没有参数并获得结果。
这意味着错误只能在 $ companiesSQL $ params

I know that the connection works because I am able to call a different stored procedure in that table that has no parameters and get results. This means that the error can only be inside of $companiesSQL or $params

I'内d还想提到我已经完成了最初的4-5页google尝试了无数不同的想法,包括微软的例子,从SP获得结果( http://technet.microsoft.com/en-us/library/cc626303(v = sql.105)。 aspx )甚至PHP的官方网站及其评论。

I'd also like to mention that Ive gone through a tleast the first 4-5 pages of google trying countless different ideas I have read including Microsoft's example on getting results from a SP (http://technet.microsoft.com/en-us/library/cc626303(v=sql.105).aspx) and even PHP's official website and its comments.

* edit
我还应该提一下,如果我登录到MSSQL Server Management studio,并从那里运行存储过程,然后它就可以了。

*edit I should also mention that if I login to MSSQL Server Management studio, and run the stored procedure from there, then it works.

我在这里做错了什么?

推荐答案

尝试将OUT参数添加到$ params数组。

Try adding OUT parameter to the $params array.

在此查看参考:
http://forums.devshed.com/php-development-5/php-mssql-sqlsrv-stored-procedure-943084.html

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

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