1

I'm trying to run a stored procedure using PHP and PDO, and I ran into an issue where not all statements in the SP are run. For my example, I tried to do 320 simple insert statements, and PDO only got through 317 of them.

Here's the SP:

CREATE  PROCEDURE TestSP
AS 
BEGIN 
insert into TestTable values (1)
-- ~314 rows later...
insert into TestTable values (316)
insert into TestTable values (317)
-- PDO stops here
insert into TestTable values (318)
insert into TestTable values (319)
insert into TestTable values (320)
END

Here's the PHP code:

$connection = new PDO(
  "sqlsrv:server=localhost ; Database=TestDb",
  "username",
  "password"
);
$stmt = $connection->prepare('EXEC TestSP');
$stmt->execute();

When I run the same EXEC statement using an MSSQL connection, the entire SP runs.

Does anyone have any idea what's going on here? Please ask questions if I need to provide more information.

FYI I did try "Call TestSP" and it would not work at all.

Edit: tried a script with a loop (I'm pretty new to scrpting in SQL)

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

IF EXISTS (SELECT *
           FROM   sys.objects
           WHERE  object_id = Object_id(N'TestSP')
                  AND type IN ( N'P', N'PC' ))
  DROP PROCEDURE TestSP
GO

CREATE  PROCEDURE TestSP
AS 
BEGIN 
DECLARE
    @counter int

SET @counter = 1
WHILE (@counter <= 500)
    BEGIN
        insert into TestTable values (@counter)
        set @counter = @counter + 1
    END
END
GO

Makes it a bit easier to test. Funny thing is I only got 108 rows from PDO, still got the whole thing from MSSQL.

4

0 に答える 0