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
S开发者_开发问答ET 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.
You are using the mssql library for each db call, but the msql library to fetch the error - is this correct?
精彩评论