我一直在研究PHP腳本,利用幾個不同的提交按鈕來更新,編輯和刪除SQL數據庫中的表信息。最近我一直在收到這個錯誤。調試我無法修復的錯誤
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 30720 bytes) in /home/peroral/public_html/InsertProducts.php on line 46
我曾經試圖得到它的工作在我的PHP文件中使用ini_set("memory_limit","128M");
試過了,但沒關係,我是多麼的內存分配(我已經上漲到512)我仍然得到錯誤。有沒有人有任何建議讓我的腳本工作?
這是我的代碼。
<!DOCTYPE html>
<html lange="en">
<!--orders.php-->
<html>
<head>
<title> InsertProducts.html form </title>
<meta charset="utf-8">
</head>
<body>
<?php
ini_set("memory_limit","128M");
require 'InsertProducts.php';
$db = DB::connect('mysql://peroal:*******@localhost/peroral');
if (DB::isError($db))
{die("Cannot Connect " . $db->getMessage());}
extract($_POST);
if(isset($create))
{
$q = $db->query("Create Table Products
id MEDIUMINT NOT NULL AUTO_INCREMENT, PRIMARY KEY (id), Product_Name VARCHAR (255), Product_Type VARCHAR (50), Product_Price DECIMAL (4,2), LOR INT");
VALUES ('$Name', '$Type', $Price, $LOR);
if (!$q)
die("Unable to Create Table." . $q->getMessage());
else
print("Table Was Created.<br />");
}
else if(isset ($delete))
{ $q = $db ->query("DROP TABLE Products");
if($q)
print("Table Products Was Deleted.<br />");
else
print ("Unable to Delete Products Table.<br />");
}
else if (isset ($add))
{ $q = $db ->query("INSERT INTO Products (Product_Name, Product_Type, Product_Price, LOR);
VALUES ('$name, $type, $price, $lor)");
if(!$q)
print ("Query Failed.<br />");
else
print ("Query Successful.<br />");
}
else if (isset ($update))
{ $q = $db ->query ("UPDATE Product_Name, Product_Type, Product_Price, LOR");
if(!q)
print ("Query Failed.<br />");
else
print ("Query Successful.<br />");
}
else if (isset ($display))
{ $sql = "SELECT Product_Name, Product_Type, Product_Price, LOR FROM products WHERE price >= $min_price
AND price <= $max_price AND Product_Name LIKE '$name'";
if($LOR == 'Liquor')
$sql.='AND LOR=1';
else
$sql.='AND LOR=0';
}
print '<table>';
print '<tr><th>Name</th><th>Type</th><th>Price</th><th>LOR</th>';
while ($row =$q->fetchRow())
{
$numberOfRows++;
if($row[3] ==1)
{
$LOR="Liquor";
}
else
{
$LOR="Beer";
}
print"<tr>";
print"<td>$row[0]</td><td>$row[1]</td><td>$row[2]</td><td>$LOR</td>";
print "</tr>";
}
print'</table>';
if($numberOfRows == 0)
print"No Match Found";
?>
</body>
</html>
?>
你有GOOGLE上搜索,甚至一個解決方案嗎?這已經被問了很多次了。 http://www.groovypost.com/howto/howto/how-to-solve-php-fatal-error-allowed-memory-size-of-8388608-bytes-exhausted/ – 2013-04-26 02:23:45
這就是我得到ini_set(「memory_limit 」, 「128M」);碼。 – user2322110 2013-04-26 02:27:56
請勿使用'extract($ _ POST)'。這真的很危險。黑客可以直接覆蓋變量的代碼 – hek2mgl 2013-04-26 02:28:18