我有 2 个脚本在技术上是相同的,但一个有效,另一个产生错误:
( ! ) Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 64 bytes) in C:\wamp\www\SOTag\SOTag.php on line 29
第 29 行是:
$rows[] = $r;
这是有效的代码:
$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);
这就是我需要做的(因为我需要检查结果)但它失败了:
$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);