時允許內存耗盡我有2個腳本這在技術上是相同的,但一個工作,另一個產生錯誤:PHP PDO分配64個字節
(!) 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);
爲什麼你使用'而($ R =而($ R = $ statement-> fetch(PDO :: FETCH_ASSOC)){'? –
對不起,我會編輯 – Adam
你確定你的第一個片段有效嗎? –