MS SQL resource result invalid

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Enga
Forum Newbie
Posts: 8
Joined: Mon Nov 21, 2005 6:17 am

MS SQL resource result invalid

Post 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
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post 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 
}
Enga
Forum Newbie
Posts: 8
Joined: Mon Nov 21, 2005 6:17 am

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Enga
Forum Newbie
Posts: 8
Joined: Mon Nov 21, 2005 6:17 am

Post 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
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post 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.
waskelton4
Forum Contributor
Posts: 132
Joined: Mon Sep 09, 2002 6:42 pm

Post 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
waskelton4
Forum Contributor
Posts: 132
Joined: Mon Sep 09, 2002 6:42 pm

Post 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
waskelton4
Forum Contributor
Posts: 132
Joined: Mon Sep 09, 2002 6:42 pm

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I'd still bank on you having some code that overwrites the variable somehow.
waskelton4
Forum Contributor
Posts: 132
Joined: Mon Sep 09, 2002 6:42 pm

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

that doesn't change my thoughts. Variables can be overwritten anywhere in PHP given the right combination.
waskelton4
Forum Contributor
Posts: 132
Joined: Mon Sep 09, 2002 6:42 pm

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

that certainly may be a clue.
waskelton4
Forum Contributor
Posts: 132
Joined: Mon Sep 09, 2002 6:42 pm

Post 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
Post Reply