为什么 MSSQL 过程在 Management Studio 和 PHP 中的调用方式不同?
Why does MSSQL procedure act differently called from Management Studio and from PHP?
我有一个主程序,它调用子程序。主程序没有参数,它只调用子程序。 (子程序相同,参数不同)
子过程从视图进行插入和更新。如果我从 Management Studio 运行 一切正常,3 分钟后我收到大约 1000 条消息“(1 行受影响)”。
但是当我从 PHP 调用它时,它 运行s 大约 1 秒没有错误,只有第一个子过程有效。如果我删除第一个程序,则只有第二个程序有效。
PHP 使用与 Management Studio 相同的用户。
If I run from Management Studio everything seems ok, after a 3 minutes I have about 1000 message says '(1 row(s) affected)'. But when I call it from PHP, then it runs for about 1 seconds with no error, and only the first sub-procedure has an effect.
您在 SSMS 中看到的“(1 行受影响)”消息是对发送给客户端的 message 的响应。如果客户端不使用这些消息,它可以阻止服务器端执行。
尝试在主程序的开头添加 set nocount on,并在 SSMS 中验证行计数消息是否已消失:
SET NOCOUNT ON prevents the sending of DONE_IN_PROC messages to the
client for each statement in a stored procedure. For stored procedures
that contain several statements that do not return much actual data,
or for procedures that contain Transact-SQL loops, setting SET NOCOUNT
to ON can provide a significant performance boost, because network
traffic is greatly reduced.
我有一个主程序,它调用子程序。主程序没有参数,它只调用子程序。 (子程序相同,参数不同) 子过程从视图进行插入和更新。如果我从 Management Studio 运行 一切正常,3 分钟后我收到大约 1000 条消息“(1 行受影响)”。 但是当我从 PHP 调用它时,它 运行s 大约 1 秒没有错误,只有第一个子过程有效。如果我删除第一个程序,则只有第二个程序有效。 PHP 使用与 Management Studio 相同的用户。
If I run from Management Studio everything seems ok, after a 3 minutes I have about 1000 message says '(1 row(s) affected)'. But when I call it from PHP, then it runs for about 1 seconds with no error, and only the first sub-procedure has an effect.
您在 SSMS 中看到的“(1 行受影响)”消息是对发送给客户端的 message 的响应。如果客户端不使用这些消息,它可以阻止服务器端执行。
尝试在主程序的开头添加 set nocount on,并在 SSMS 中验证行计数消息是否已消失:
SET NOCOUNT ON prevents the sending of DONE_IN_PROC messages to the client for each statement in a stored procedure. For stored procedures that contain several statements that do not return much actual data, or for procedures that contain Transact-SQL loops, setting SET NOCOUNT to ON can provide a significant performance boost, because network traffic is greatly reduced.