Jump to content

Warning: Unknown: 1 result set(s)


Kristian_C

Recommended Posts

Hmm, i dont know this type of error, anyone knows what it is? :s.. the whole error is :Warning: Unknown: 1 result set(s) not freed. Use mysql_free_result to free result sets which were requested using mysql_query() in Unknown on line 0-Kristian_C

Link to comment
Share on other sites

I didn't know that PHP would produce a warning like that.The message means that you created a mysql result set using mysql_query ($result = mysql_query(...)). Like everything else, the result set takes up space in memory. The warning is saying that you have a result that was not freed from memory (mysql_free_result($result)). But, I don't know under what circumstances PHP would issue a warning about that. When the script ends all of the resources will be freed from memory anyway, so I'm not sure what would trigger this as a warning. The lack of a file and line number seems to indicate that the PHP processor is detecting at the end of execution that there are unfreed resources, but - again - I'm not sure why it would issue a warning instead of just freeing the memory at that point. Like boen said, please post the code that is causing this.

Link to comment
Share on other sites

Lol, soon ive posted all codes i got on w3schools forum :) hehe...Well, every code i use while($someting=mysql_fetch_object($someotherthing)){ or while($something=mysql_num_rows($someotherthing)){ or $something=mysql_fetch_object($someotherthing); or $something=mysql_numrows($someotherting);but since you asked for the code, here it is :

<html><head><title>New York Assassins - .::BETA::.</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><link href="css/matrix.css" rel="stylesheet" type="text/css" /></head><body><?php $new=mysql_query("SELECT * FROM nyheter WHERE aktiv='Ja'");	  while($nyhett=mysql_fetch_object($new)){	print <<<ENDHTML <div class="main-header">Tittel : $nyhett->tittel Dato : $nyhett->tid</div><div class="main-content">  <table width="100%" border="0" cellpadding="0" cellspacing="0">	<tr>	  <td width="748" valign="top"><span class="tekst">.bbkode($nyhett->tekst).</span><br>	  <br><a href="?xx=forside.php&x=lesmer&id=$nyheter->id">Les Mer...</a></td>	  <td width="215"></td>	  <td width="210" valign="top"><span class="tekst"><img src="$nyhett->bilde" alt="ll" width="209" height="225" class="image"></span></td>	</tr>  </table></div>ENDHTML;}?><?phpif($bruker->level=="Administrator"){if(isset($_POST['leggtil'])){$tittel=$_POST['tittel'];$nyhet=$_POST['nyhet'];$bilde=$_POST['bilde'];mysql_query("INSERT INTO nyheter(id,brukernavn,tid,tittel,tekst,aktiv,bilde)VALUES('','$bruker->brukernavn','$tid','$tittel','$nyhet','Ja','$bilde')") or die("Error :<br> " .mysql_error());echo"<div class=\"main-header\">Nyheter</div>	 <div class=\"main-content\">Nyhet er lakt til</div>";}?><div class="main-header">Nye Forside Nyheter</div><div class="main-content">  <table width="451" border="0">	  <tr>		<td width="61" height="74" valign="top">		<span class="tekst">Tittel :<br> 		Bilde <br>	   		Nyhet :</span></td>		<td width="380" align="left">				  <div align="left"><form method="post" name="form2">			<input name="tittel" type="text" class="input-forside" size="43" maxlength="25">			<br>			<input name="bilde" type="text" class="input-forside" size="43" maxlenght="40">			<br>			<textarea name="nyhet" cols="45" rows="4" class="input-forside"></textarea>			<br>			<input type="submit" name="leggtil" class="input-forside" value="Legg ut nyheter"></form>		  </div></td>	  </tr>	</table></div><?php}?></body></html>

I asked my host to set all errors and warnings to be displayd at my site, think thats why, never ever got a warning like that with any other hosts, but the reason i asked him to do this is that even if show errors was on in php.ini it whould not show errors...Hope you guys can help me with this as you have helped me with everything else, whould'ent be anything without you, so thanks :).-Kristian_C

Link to comment
Share on other sites

The only result you have is here:$new=mysql_query("SELECT * FROM nyheter WHERE aktiv='Ja'");So you would use mysql_free_result after you're done using $new. Most people will ignore warnings like this just because the server normally doesn't show them, and PHP will clean up after itself, but it is a better practice to always free up memory when you're done using it so that if you have several scripts including each other or something they won't max out the memory on the server. If the scripts free up memory as soon as it is no longer needed then it will run with a smaller memory footprint, so more scripts can run at the same time or more people can use the site at once.

Link to comment
Share on other sites

Well, you know how when you perform a mysql_query it returns a resultset as a resource. While that data is still stored in the server's memory, it takes up space, and so to free that space and improve performance you can delete that resource. But you will not be able to recall on the result (e.g. $new as above) after you call mysql_free_result(). No permanent data, however, is lost.

Link to comment
Share on other sites

Ok, was reading abit on php.net and some people said that the mysql_free_result() made their db to use more memory, so just turnet off the trace.mysql something in php.ini... If i find out that i absolutly should have it i will add it, but as i have "alot" of db space i think it wont be a problem in the start...Thanks for help and answers guys :)

Link to comment
Share on other sites

You should have it, the code is "more correct" if you have it. Ideally, you would be able to run your code with all warnings and notices being shown and not have the code cause any warnings or notices to show up. This is one of those things you can do to help make your code more efficient. The space that is being taken up, and the space that mysql_free_result frees up, is only the server's main memory (RAM). It is not hard drive space, it is not the space that your database is taking up on disk. Using mysql_free_result in fact does not interact with the MySQL server at all, all it does is allow the web server to release the memory space that the MySQL result was taking up in memory to make that memory available to something else that needs it. It doesn't affect your database at all, it only makes your code more efficient. There is no danger or downside to using this function, and someone saying that it causes their database to use more memory is wrong. First off, it's very difficult to even determine how much memory is allocated to MySQL. This is memory we're talking about, not hard drive space. Someone saying that this function is causing a side-effect like that is probably putting the blame for one problem somewhere else, this function does not cause the database to use any more (or less) space on the hard drive. I saw that comment on the reference page, and the query that the guy is using is probably not returning a very large result set if he's saving 208 bytes in memory by not using the function.But, like the reference page says:

mysql_free_result() only needs to be called if you are concerned about how much memory is being used for queries that return large result sets.
This holds for any resource, not just mysql resources. You always want to free up large data structures as soon as you can. I was building a script that reads an uploaded Excel file and does a bunch of work with values in the different sheets, and for a large Excel file it was taking up way to much memory by the time the script finished. So as the script was going I would use unset to delete arrays and things that were filled with all the data from the Excel file that was no longer needed. Things like this just make your application more efficient, it's always better to free up large data structures when you are finished using them.
Link to comment
Share on other sites

Okay, so what you are saying is that if im useing much scripts that runs all the time i should use it?!?... Then i think it whould be the best for me to use it :).. The scripts im creating will be used by around 100-1500people every day, or more... Thank you once again for beeing so helpful :)...-Kristian_C.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...