0

I don't understand why this piece of code miserably fails. The first pass of the for() loop works fine but in the second pass mssql_query() fails, no errors are reported and the program just die.

for($i=0; $i <2; $i++){
       $query = "SELECT * FROM Viaggio ";
       $result = mssql_query($query, $link) or die("query fallita:".msql_error());
          if( mssql_num_rows($result) ){
             while($row = mssql_fetch_array($result, MSSQL_ASSOC)){
                echo 'blablablabla' . $row[some_index] . 'blabla';
             }
          }
    }

I don't know why this happen, It's works with all the other tables in my database except for Viaggio. This is the CREATE TABLE query directly from msSQL:

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[Viaggio](
 [codViaggio] [bigint] IDENTITY(0,1) NOT NULL,
 [data] [smalldatetime] NOT NULL,
 [oraArrivo]  AS ([data]+[durata]),
 [corsaExpress] [bit] NOT NULL,
 [durata] [time](7) NOT NULL,
 [fascia] [nvarchar](50) NOT NULL,
 [distanza] [char](3) NOT NULL,
 [nave] [nvarchar](50) NOT NULL,
 [partenza] [nvarchar](50) NOT NULL,
 [arrivo] [nvarchar](50) NOT NULL,
 CONSTRAINT [PK_Viaggio] PRIMARY KEY CLUSTERED 
(
 [codViaggio] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

ALTER TABLE [dbo].[Viaggio]  WITH CHECK ADD  CONSTRAINT [FK_Viaggio_Nave] FOREIGN KEY([nave])
REFERENCES [dbo].[Nave] ([nome])
ON UPDATE CASCADE
GO

ALTER TABLE [dbo].[Viaggio] CHECK CONSTRAINT [FK_Viaggio_Nave]
GO

ALTER TABLE [dbo].[Viaggio]  WITH CHECK ADD  CONSTRAINT [FK_Viaggio_Rotta] FOREIGN KEY([partenza], [arrivo])
REFERENCES [dbo].[Rotta] ([pPartenza], [pArrivo])
ON UPDATE CASCADE
ON DELETE CASCADE
GO

ALTER TABLE [dbo].[Viaggio] CHECK CONSTRAINT [FK_Viaggio_Rotta]
GO

ALTER TABLE [dbo].[Viaggio]  WITH NOCHECK ADD  CONSTRAINT [FK_Viaggio_Tariffa] FOREIGN KEY([fascia], [distanza])
REFERENCES [dbo].[Tariffa] ([fascia], [distanza])
ON UPDATE CASCADE
GO

ALTER TABLE [dbo].[Viaggio] CHECK CONSTRAINT [FK_Viaggio_Tariffa]
GO

Thank you very much

[EDIT] I just tried to use mssql_free_result() but also this function crash the program.

4
  • I'm not sure whether this will do the trick but: "SELECT * FROM Viaggio;" - notice the semicolon Commented Jan 3, 2010 at 18:02
  • @Gal - the semicolon shouldn't matter, as there is only one statement per issued query Commented Jan 3, 2010 at 18:07
  • 1
    @afftee - the question states that there is no error message Commented Jan 3, 2010 at 18:07
  • Which version of php and SQLServer do you use? What's the version phpinfo() reports for the mssql library? Commented Jan 3, 2010 at 19:25

1 Answer 1

1

You are using the mssql library for each db call, but the msql library to fetch the error - is this correct?

Sign up to request clarification or add additional context in comments.

8 Comments

I don't know if this is correct (I think no) but if i remove the "or die..." option nothing changes.
Why are you looping through the code twice? Try outputting mssql_num_rows($result)
The first time mssql_num_rows return 12 (the correct number of records in the table Viaggio) the second time the program hangs on mssql_query(). Nothing is returned from mssql_query() calls and the program dies.
It sounds like the mssql server is tripping out or taking too long to reply. You could try increasing the php script time limit with set_time_limit. Again, if you're looping through the same query twice then why not just query once and reuse the initial results?
Ok thank you very much, the problem was the mssql databese we HAVE to use is in a very crappy server. Adjusting the set_time_limit works well! Obviously I need to looping through the same query but with different condition each time, I just simplified the query for posting :)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.