mysql caching from my own php function -


hello: have function one

function query($query) {     if (in_array($query,$this->queries))     {             return $result = $this->results[$query];     }      $this->queries[] = $query;     $result = mysql_query($query);     if ($result)     {             while($row = mysql_fetch_array($result)             {                     $this->results[$query][] = $row;             }              //i need return $result later use (so can loop in while if need later)             //but problem $result being cleaned after fetching      } } 

does anybody/anyone know solution?

you getting array of results in function shouldn't use mysql_fetch_assoc. instead, loop through results (assuming there results):

function query($query) {     if (in_array($query,$this->queries))     {         return $result = $this->results[$query];     }      $this->queries[] = $query;     $result = mysql_query($query);     if ($result)     {         while($row = mysql_fetch_assoc($result)         {             $this->results[$query][] = $row;         }          return $this->results[$query];     } } 

and use:

$result = query("select * test");  if(count($result) > 0) {     foreach($result $key=>$value)     {         // need rows     }    } 

Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -