Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7941575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:42:42+00:00 2026-06-03T23:42:42+00:00

I have a stored procedure running in MS SQL 2008 R2 which runs fine

  • 0

I have a stored procedure running in MS SQL 2008 R2 which runs fine in SQL Management Studio. However, if I run it from PHP it seems to stop execution before finishing. There is no error returned in SQL and no error returned in the PHP error log. The procedure simply writes to an error log a number of times using a second stored procedure. I have cut the code down to a simple loop to demonstrate reproducing the problem. This is the main stored procedure.

ALTER PROCEDURE [dbo].[usp_failure_test]

AS
DECLARE
@counter int,
@message nvarchar(100)

SET @counter = 0;
WHILE @counter < 100
  BEGIN
    SET @message = 'COUNT: ' + CAST(@counter AS nvarchar);
    EXEC usp_log 0, 'TEST', @message;
    SET @counter += 1;
  END
EXEC usp_log 0, 'TEST', 'Finished';

This calls the procedure usp_log

ALTER PROCEDURE [dbo].[usp_log]
@engine_id int,
@type nvarchar(15),
@message text
AS
DECLARE
@last int,
@log_size int

INSERT INTO [dbo].[log] (engine_id, timestamp, type, message) VALUES (@engine_id, getdate(), @type, @message);
SET @log_size = CONVERT(int, (dbo.get_setting('log_size')))
SET @last = (SELECT TOP 1 id FROM log ORDER BY id DESC)
DELETE FROM log WHERE id < (@last - @log_size)
return

If I execute usp_failure test from SSMS it writes all of the expected log entries and then stops successfully. However, if I execute it from PHP (with the following code), it only reaches 52 and then stops without any clue as to why.

<?php
$servername = "localhost\sqlexpress";
$connectionInfo = array("UID" => "xxx", "PWD" => "xxx", "Database"=>"xxx", "ReturnDatesAsStrings"=>true, "CharacterSet" =>"UTF-8");
$conn = @sqlsrv_connect($servername, $connectionInfo);
$query = "usp_failure_test";
$params = array();
$result = sqlsrv_query($conn, $query, $params);
?>

I have tried adding in extra lines of code and this makes it fail after even fewer iterations. I have ensured that PHP has plenty of memory to work with and I’ve also checked the PHP and SQL logs to no avail. We’ve also used SQL profiler which did not show up any issues either.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T23:42:44+00:00Added an answer on June 3, 2026 at 11:42 pm

    Try using SET NOCOUNT ON in your stored procedures. You are likely hitting a limit on the number of results that can be returned to PHP from the sql server PHP driver.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a stored procedure running on sql server 2008 looping over a table
I have a very long-running stored procedure in SQL Server 2005 that I'm trying
I have a somewhat-long-running stored procedure being called from a PB application. I want
I have an application running in IIS which connects to a SQL Server 2008
I have a stored procedure in SQL Server 2008 that will insert a record
Using SQL Server 2008 I created a Stored Procedure called MyStoreProc and it runs
The problem is I have a stored procedure that runs consistently in Sql Server
I've written a stored procedure that takes 15 min when executed from Management Studio.
I am running a stored procedure in SQL Server 2008 inside a try/catch. The
I am running SQL Server and I have a stored procedure. I want do

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.