我正在使用一些PHP和MSSQL,这是一个非常奇怪的问题。我正在使用存储过程来检索用户刚刚存储到数据库中的信息,以便他们可以打印出他们输入的记录。
最初我遇到了在屏幕上显示标题详细信息的问题,因此最终通过将$ skip_results的布尔值设置为true来更改代码。这意味着我必须在没有该设置的情况下第二次调用存储过程以获取相关的信息行。
这就是我的所作所为:
//populate header with order information - this one uses true in the mssql_execute in order to return all the output variables
/* prepare the statement resource */
$confirmationstmt=mssql_init("stored-procedure-name", $link);
/* now bind the parameters to it */
mssql_bind($confirmationstmt, "@var1", $var1, SQLVARCHAR, FALSE);
mssql_bind($confirmationstmt, "@var2", $var2, SQLFLT8, TRUE);
mssql_bind($confirmationstmt, "@var3", $var3, SQLVARCHAR, TRUE);
mssql_bind($confirmationstmt, "@var4", $var4, SQLVARCHAR, TRUE);
mssql_bind($confirmationstmt, "@var5", $var5, SQLVARCHAR, TRUE);
mssql_bind($confirmationstmt, "@var6", $var6, SQLVARCHAR, TRUE);
mssql_bind($confirmationstmt, "@var7", $var7, SQLVARCHAR, TRUE);
mssql_bind($confirmationstmt, "@var8", $var8, SQLINT4, TRUE);
mssql_bind($confirmationstmt, "@var9", $var9, SQLVARCHAR, true);
mssql_bind($confirmationstmt, "@var10", $var10, SQLFLT8, true);
mssql_bind($confirmationstmt, "@var11", $var11, SQLFLT8, true);
mssql_bind($confirmationstmt, "@var12", $var12, SQLFLT8, true);
mssql_bind($confirmationstmt, "@var13", $var13, SQLFLT8, true);
// now execute the procedure
$confirmationresult = mssql_execute($confirmationstmt, true);
//populate header with order information - this one uses true in the mssql_execute in order to return all the output variables
/* prepare the statement resource */
$numlinesstmt=mssql_init("stored-procedure-name", $link);
/* now bind the parameters to it */
mssql_bind($numlinesstmt, "@var1", $var1, SQLVARCHAR, FALSE);
mssql_bind($numlinesstmt, "@var2", $var2, SQLFLT8, TRUE);
mssql_bind($numlinesstmt, "@var3", $var3, SQLVARCHAR, TRUE);
mssql_bind($numlinesstmt, "@var4", $var4, SQLVARCHAR, TRUE);
mssql_bind($numlinesstmt, "@var5", $var5, SQLVARCHAR, TRUE);
mssql_bind($numlinesstmt, "@var6", $var6, SQLVARCHAR, TRUE);
mssql_bind($numlinesstmt, "@var7", $var7, SQLVARCHAR, TRUE);
mssql_bind($numlinesstmt, "@var8", $var8, SQLINT4, TRUE);
mssql_bind($numlinesstmt, "@var9", $var9, SQLVARCHAR, true);
mssql_bind($numlinesstmt, "@var10", $var10, SQLFLT8, true);
mssql_bind($numlinesstmt, "@var11", $var11, SQLFLT8, true);
mssql_bind($numlinesstmt, "@var12", $var12, SQLFLT8, true);
mssql_bind($numlinesstmt, "@var13", $var13, SQLFLT8, true);
// now execute the procedure
$numlinesresult = mssql_execute($numlinesstmt);
$numlines = mssql_num_rows($numlinesresult);
第一组mssql_bind语句中的变量都已正确填充,虽然您希望第二次调用覆盖它们,但它们不会!当我第一次将这个“修复”应用到站点时,正确填充了$ numlines变量,这使我可以处理存储过程创建的select语句带回的所有行。但是,24小时后第二组停止工作,我从mssql_num_rows($ numlinesresult)调用中得到一个0。
任何人都可以告诉我这里做错了什么,因为我真的不应该两次调用存储过程,每次都以不同的方式,以便获取所有信息。
提前致谢!
答案 0 :(得分:2)
存储过程包含SET NOCOUNT ON