Page 1 of 1

MS SQL resource result invalid

Posted: Thu Jan 26, 2006 9:46 am
by Enga
Hey!

I'm having some troubles with some code about a resource result thar decided not to be valid when passed to a linux box 8O

I use a special Object to access tha database cause its suposed to use a mssql or a mysql databse.
the error message is : mssql_fetch_array(): 11 is not a valid MS SQL-result resource
and refers the my special DB access Object (dal) in line 11 wich is

Code: Select all

function fetchArray($result)
{
  global $MSSQL;
if($MSSQL)
{
    $row = mssql_fetch_array($result, MSSQL_ASSOC);
    return $row;
}
else
...//the same for mysql
}
this is a simpliest show of the code that calls the function above:

Code: Select all

while($row=$objDAL->fetchArray($rst))           
               $listagem->Referencias($row,"Pesquisa",$txtAutores);


so what is the problem? :?

Everthing works fine in windows but in my FC4 box i only get the first row of the $rst, in the second iteration the error occurs.

anyone?
Thanks

Pedro Barbosa

Posted: Thu Jan 26, 2006 6:29 pm
by raghavan20
Try this and post error/s if they occur

Code: Select all

function fetchArray($result) 
{ 
//  global $MSSQL; 
//if($MSSQL) 
//{ 
  if (is_resource($result)){
    $row = mssql_fetch_array($result, MSSQL_ASSOC); 
    return $row; 
} 
else 
...//the same for mysql 
}

Posted: Fri Jan 27, 2006 3:57 am
by Enga
Now it skips to the else statement ...but thats not what i really wanted :?

i really cant understand why at some point php inisist that $result is no longer a valid result resource.

I was basically destroying my code to find some error and took the code from my object $listagem and put it in the while statement and it started working 8O
WHYYY ??? :x

What's the problem when using classes?

Anyone had similar problems?

Pedro Barbosa

Posted: Fri Jan 27, 2006 6:43 am
by feyd
are you sure you are not overwriting $result?

trying using var_export() or var_dump() on $result for each call to that function. You may find that you used $result somwhere else inbetween.

Posted: Fri Jan 27, 2006 11:23 am
by Enga
Im sure he was not overwriting the variable i decided to gave up using OO and put it all back with tipical includes and some auxiliar functions that solved the problem.
now i know why windows is the prefered OS to most people ...

thanks everyone for the help

Posted: Fri Jan 27, 2006 2:35 pm
by raghavan20
Enga wrote:Im sure he was not overwriting the variable i decided to gave up using OO and put it all back with tipical includes and some auxiliar functions that solved the problem.
now i know why windows is the prefered OS to most people ...

thanks everyone for the help
Not because someone is not able to find the problem with OO, you cannot give up OO and similarly use of OO is not beneficial unless it is properly used. If anyone want to prove OO is powerful, first post all the relevant code and the link to the working file.

Posted: Wed Feb 08, 2006 1:14 pm
by waskelton4
Me too..

This looks almost exactly like a problem i'm having.

Using MSSQL 2000 and IIS6 on win2k3 server.

i'm using a view created on the server currently but it did the same thing without the view..
the

Code: Select all

while($row = mssql_fetch_object($result))
will loop through twice and on the third time gives a warning that
Warning: mssql_fetch_object(): 23 is not a valid MS SQL-result resource...
When I echo the query being run and run it in mssql query analyzer.. it returns all the rows it is supposed.. (more than 2)

I tried what was mentioned above and changed the beginning of the loop to

Code: Select all

while(is_resource($result)){
$row = mssql_fetch_object($result);
....
produced the same two rows but removed the warning.

I'm not doing anything within the loop but displaying the object variables via

Code: Select all

<?=$row->varName?>
Any Ideas on why this might be happening.

Did you get your problem fixed Pedro?

Thanks
Will

Posted: Wed Feb 08, 2006 1:39 pm
by waskelton4
additional info..

if i use mssql_num_rows to get the number of rows returned. then use that number and a for loop to produce the rows, on the third row it displays the row but not the data in that row.. then it throws a fatal error because a function that i'm calling didn't get it's required value.

ws

Posted: Thu Feb 09, 2006 8:19 am
by waskelton4
The more and more I think about this.. the more I think it is a bug in PHP..

any thoughts on that?
ws

Posted: Thu Feb 09, 2006 9:39 am
by feyd
I'd still bank on you having some code that overwrites the variable somehow.

Posted: Thu Feb 09, 2006 9:47 am
by waskelton4
feyd wrote:I'd still bank on you having some code that overwrites the variable somehow.
Well,
I changed the variable name from $result to $result2 and still had the same problem..

ws

Posted: Thu Feb 09, 2006 9:54 am
by feyd
that doesn't change my thoughts. Variables can be overwritten anywhere in PHP given the right combination.

Posted: Thu Feb 09, 2006 9:58 am
by waskelton4
i'll take another look at it and get back..

also.. would it matter that it used to work using mssql_fetch_array instead of mssql_fetch_object?

ws

Posted: Thu Feb 09, 2006 9:59 am
by feyd
that certainly may be a clue.

Posted: Fri Feb 10, 2006 11:17 am
by waskelton4
Thanks for sticking to your guns feyd..

I had a couple of functions i was calling that both had $result used in them. change that out and it worked fine.

thanks for your help.... again :)

Will