I am using a search that is using a lot of memory. I use mysql_pconnect(). I want to use... or I believe I should use mysql_free_result() to free up the memory after the code is done. Here is a simplified example of a search I might do? How would I apply mysql_free_result() to free up the memory effectively?

$sql = mysql_query("SELECT username, password, something1, something2, something3 FROM users WHERE username='$username' AND password='$password'");
while($row = mysql_fetch_array($sql)) {

$something1 = $row["something1"];
$something2 = $row["something2"];
$something3 = $row["something3"];
     }

    use mysql_free_result as soon as you are finished with mysql_fetch_array

      mysql_free_result isn't needed...(as can be read in the manual 😃)http://de2.php.net/manual/en/function.mysql-free-result.php

      only needs to be called if you are concerned about how much memory is being used for queries that return large result sets. All associated result memory is automatically freed at the end of the script's execution.

      Why does this simple query takes so much memory?

      Here is one of my querys - wich is searching over about 20.000 rows of data...:

      SELECT 
             EVN_Nodes.type AS Dienst,
             RIGHT(EVN_DTAG.datum, 7 ) AS Zeitraum,
             EVN_Nodes.memo AS Node,
             EVN_DTAG.zielrufnr AS Zielrufnummer,
             SUM( EVN_DTAG.nettogesamt ) AS SUMME
      FROM EVN_DTAG
         INNER JOIN EVN_Nodes ON (EVN_DTAG.anschluss = EVN_Nodes.anschluss)
      WHERE 
         (
            (EVN_Nodes.type = 'DATA')
         and 
            (RIGHT(EVN_DTAG.datum, 7 ) ='02.2004' )
         )
      GROUP BY RIGHT(EVN_DTAG.datum, 7 ), EVN_Nodes.memo, EVN_DTAG.zielrufnr, EVN_Nodes.type
      ORDER BY EVN_Nodes.memo
      

      Now it takes 2 sec. for execution. An older version took up to 50 sec. because i grouped a wrong way...
      I don't use mysql_free_result at all and it works perfect.

      Maybe, the server you are using is a bit to small for "Apache, PHP, mySQL" ... what are you using? an Intel 8086 😉 ?

        yes, I am using this because I am getting VERY large result sets and have a lot of people accessing the database at the sametime. Do I need to put anything in the brackets of mysql_free_result() ...like this-- mysql_free_result($result) ?

          Ok... do, what you want to do...

          Here is a snipet from the docu (link above):

          VALID:

          $query = "SELECT * FROM music WHERE $album=12";
          $go = mysql_query( $query ) or die( 'SELECT failed' );
          // Free result memory, since we don't need it
          mysql_free_result( $go );

          our website has about 4000 Visitors a day... we don't use mysql_free_result... it works...

          But, as is said: Do what you want to do 😃

            Write a Reply...