php - One line of my script using all available memory - why? -


i have php project i'm making, i've hit dead end 1 line causing script error out saying memory limit has been exausted.

the line in question part of method, follows:

public function query_all($query) {      if (function_exists('mysqli_fetch_all')) # compatibility layer php < 5.3         $res = mysqli_fetch_all($this->query($query));     else     ($res = array(); $tmp = mysqli_fetch_array($this->query($query));) $res[] = $tmp;      return $res; } 

this function part of class named db, line error line loop:

for ($res = array(); $tmp = mysqli_fetch_array($this->query($query));) $res[] = $tmp; 

this function called once in code, @ top of else statement:

do     {         $id = rand(1000000, 9999999);          if (!util::in_array_r($id, $db->query_all('select * tickets')))         {             break;         }     }     while (true);      $emailsubject = $db->escape($emailsubject);     $emailbody = $db->escape($emailbody);     $from = $db->escape($from);      $db->query("insert tickets values ($id, '$emailsubject', '$emailbody', '$from')");       foreach ($config['staff_emails'] $email)     {         mail($email, "[$id] [new ticket] $emailsubject", $emailbody, "reply-to: $to");     } 

i don't understand why doing - never used to, , thing changed making sql queries work :/

does know why happening? loop running endlessly? database contains 1 row though, don't see how could,

thanks, liam

you have infinite loop. want do

while ($row = mysqli_fetch_array($this->query($query)) {     $res[] = $row; 

instead of

for ($res = array(); $tmp = mysqli_fetch_array($this->query($query));) $res[] = $tmp; 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -