I have 2 scripts which are technically the same, but one works, and the other produces the error:
( ! ) Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 64 bytes) in C:\wamp\www\SOTag\SOTag.php on line 29
Line 29 being:
$rows[] = $r;
This is the code that works:
$this->connect_db();
$statement = $this->db_connection->prepare("SELECT * FROM tags WHERE tag LIKE :keywords");
$statement->bindParam(':keywords', $keywords, PDO::PARAM_INT);
$statement->execute(compact('keywords'));
$rows = array();
while($r = $statement->fetch(PDO::FETCH_ASSOC)) {
$rows[] = $r;
}
return json_encode($rows);
And this is what I need to do (as I need to check for results) but it fails:
$this->connect_db();
$statement = $this->db_connection->prepare("SELECT * FROM tags WHERE tag LIKE :keywords");
$statement->bindParam(':keywords', $keywords, PDO::PARAM_INT);
$statement->execute(compact('keywords'));
$result = $statement->fetch(PDO::FETCH_ASSOC);
$rows = array();
while($r = $result) {
$rows[] = $r;
}
return json_encode($rows);