|
|
|
โค๊ดตัวนับ (Counter) มีปัญหาครับ มีตัวอย่างโค๊ด กับตัว Error ให้ดูครับ |
|
|
|
|
|
|
|
นี่คือส่วนที่แสดงข้อความ Error ครับ
Fatal error: Allowed memory size of 25165824 bytes exhausted (tried to allocate 524288 bytes) in C:\AppServ\www\inc\counter.inc.php on line 103
และนี่คือโค๊ดที่เขาแจ้งว่า Error
Code (PHP)
<?php
class Counter{
var $TbCounter = "tu_counter";
function SetCounter($TheIP=NULL){
if(empty($TheIP))return false;
$Field = "ip,createdate";
$Value = "'$TheIP',NOW()";
require_once("dbconnect.inc.php");
$sql = "INSERT INTO ".$this->TbCounter." ($Field) VALUES($Value)";
mysql_query($sql) or die($sql." : ".mysql_errno()." -> ".mysql_error());
unset($sql,$Field,$Value);
return mysql_insert_id();
}//End SetCounter
function Browse($TheIP=NULL,$DspCondition=NULL,$RecordStart=NULL,$RecordPerPage=NULL,$Order=NULL){
$Field = "ip,createdate";
$Condition = $ReturnResult = array();
if(!empty($TheIP)) $Condition[] = " ip='$TheIP'";
if($DspCondition=="this week") $Condition[] = " createdate BETWEEN DATE_SUB(CURDATE(),INTERVAL ".date("w")." DAY) AND NOW()";
else if($DspCondition=="last week")$Condition[] = " createdate BETWEEN DATE_SUB(CURDATE(),INTERVAL ".(date("w")+7)." DAY) AND DATE_SUB(CURDATE(),INTERVAL ".date("w")." DAY)";
else if($DspCondition=="this month") $Condition[] = " MONTH(createdate)=MONTH(CURDATE())";
else if($DspCondition=="last month")$Condition[] = " MONTH(createdate)=MONTH(CURDATE())-1";
else if($DspCondition=="this year")$Condition[] = " YEAR(createdate)=YEAR(CURDATE())";
else if($DspCondition=="last year")$Condition[] = " YEAR(createdate)=YEAR(CURDATE())-1";
if(empty($TheIP))$Field .= ",COUNT(ip) AS visit";
$sql = "SELECT $Field FROM ".$this->TbCounter;
if(count($Condition)) $sql .=" WHERE ".implode(" AND ",$Condition);
if(empty($TheIP))$sql .= " GROUP BY ip ";
if(!empty($Order)) $sql .= " ORDER BY $Order";
else $sql .= " ORDER BY createdate DESC";
if(is_numeric($RecordStart) AND is_numeric($RecordPerPage)) $sql .= " LIMIT $RecordStart,$RecordPerPage";
require_once("dbconnect.inc.php");
$result = mysql_query($sql) or die($sql." : ".mysql_errno()." -> ".mysql_error());
while($row= mysql_fetch_array($result)){
$Value = array();
for($index=0;$index<mysql_num_fields($result);$index++){
$Field = mysql_fetch_field($result,$index);
$Value[$Field->name] = $row[$Field->name];
}//End while
$ReturnResult[] = $Value;
}//End while
unset($sql,$Field,$Condition);
return $ReturnResult;
}//End Browse
function BrowseDetail($TheIP=NULL,$DspCondition=NULL,$RecordStart=NULL,$RecordPerPage=NULL,$Order=NULL){
$Field = "ip,createdate";
$Condition = $ReturnResult = array();
if(!empty($TheIP)) $Condition[] = " ip='$TheIP'";
if($DspCondition=="this week") $Condition[] = " createdate BETWEEN DATE_SUB(CURDATE(),INTERVAL ".date("w")." DAY) AND CURDATE()";
else if($DspCondition=="last week")$Condition[] = " createdate BETWEEN DATE_SUB(CURDATE(),INTERVAL ".(date("w")+7)." DAY) AND DATE_SUB(CURDATE(),INTERVAL ".date("w")." DAY)";
else if($DspCondition=="this month") $Condition[] = " MONTH(createdate)=MONTH(CURDATE())";
else if($DspCondition=="last month")$Condition[] = " MONTH(createdate)=MONTH(CURDATE())-1";
else if($DspCondition=="this year")$Condition[] = " YEAR(createdate)=YEAR(CURDATE())";
else if($DspCondition=="last year")$Condition[] = " YEAR(createdate)=YEAR(CURDATE())-1";
$sql = "SELECT $Field FROM ".$this->TbCounter;
if(count($Condition)) $sql .=" WHERE ".implode(" AND ",$Condition);
if(!empty($Order)) $sql .= " ORDER BY $Order";
if(!empty($Order)) $sql .= " ORDER BY createdate DESC";
if(is_numeric($RecordStart) AND is_numeric($RecordPerPage)) $sql .= " LIMIT $RecordStart,$RecordPerPage";
require_once("dbconnect.inc.php");
$result = mysql_query($sql) or die($sql." : ".mysql_errno()." -> ".mysql_error());
while($row= mysql_fetch_array($result)){
$Value = array();
for($index=0;$index<mysql_num_fields($result);$index++){
$Field = mysql_fetch_field($result,$index);
$Value[$Field->name] = $row[$Field->name];
}//End while
$ReturnResult[] = $Value;
}//End while
unset($sql,$Field,$Condition);
return $ReturnResult;
}//End BrowseDetail
function GetCounter($TheIP=NULL,$Date=NULL,$Month=NULL,$Year=NULL,$RecordStart=NULL,$RecordPerPage=NULL,$Order=NULL){
$Field = "ip,createdate";
$Condition = $ReturnResult = array();
if(!empty($TheIP)) $Condition[] = " ip='$TheIP'";
if(!empty($Date) && !empty($Month) && !empty($Month)) $Condition[] = " DATE_FORMAT(createdate,'%Y-%m-%d')='$Year-$Month-$Date'";
elseif(!empty($Month) && !empty($Month)) $Condition[] = " DATE_FORMAT(createdate,'%Y-%m')='$Year-$Month'";
elseif(!empty($Year)) $Condition[] = " DATE_FORMAT(createdate,'%Y')='$Year'";
$sql = "SELECT $Field FROM ".$this->TbCounter;
if(count($Condition)) $sql .=" WHERE ".implode(" AND ",$Condition);
if(!empty($Order)) $sql .= " ORDER BY $Order";
if(is_numeric($RecordStart) AND is_numeric($RecordPerPage)) $sql .= " LIMIT $RecordStart,$RecordPerPage";
require_once("dbconnect.inc.php");
$result = mysql_query($sql) or die($sql." : ".mysql_errno()." -> ".mysql_error());
while($row= mysql_fetch_array($result)){
$Value = array();
for($index=0;$index<mysql_num_fields($result);$index++){
$Field = mysql_fetch_field($result,$index);
$Value[$Field->name] = $row[$Field->name];
}//End while
$ReturnResult[] = $Value; //บรรทัดนี้ละครับที่บอกว่ามีปัญหา
}//End while
unset($sql,$Field,$Condition);
return $ReturnResult;
}//End GetCounter
function GetUserIP(){
if (isset($_SERVER)) {
if (isset($_SERVER["HTTP_X_FORWARDED_FOR"]))
return $_SERVER["HTTP_X_FORWARDED_FOR"];
if (isset($_SERVER["HTTP_CLIENT_IP"]))
return $_SERVER["HTTP_CLIENT_IP"];
return $_SERVER["REMOTE_ADDR"];
}
if (getenv('HTTP_X_FORWARDED_FOR'))
return getenv('HTTP_X_FORWARDED_FOR');
if (getenv('HTTP_CLIENT_IP'))
return getenv('HTTP_CLIENT_IP');
return getenv('REMOTE_ADDR');
}
}//End Counter
?>
Tag : PHP, MySQL
|
|
|
|
|
|
Date :
2011-09-05 15:08:13 |
By :
narak0001 |
View :
950 |
Reply :
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ไม่แน่ใจว่าเป็นที่ขนาดของไฟล์ที่จัดเก็บหรือเปล่าอะครับ
|
|
|
|
|
Date :
2011-09-05 15:16:06 |
By :
narak0001 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
แก้ memory_limit ใน php.ini แล้ว restart apache ด้วยครับ
|
|
|
|
|
Date :
2011-09-05 15:25:24 |
By :
ppanchai |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ผมต้องปรับบรรทัด 35 ใช่หรือไม่ครับ ที่มีเป็นโค๊ด
if(is_numeric($RecordStart) AND is_numeric($RecordPerPage)) $sql .= " LIMIT $RecordStart,$RecordPerPage";
แล้วผมต้องปรับแก้อย่างไรครับ
|
|
|
|
|
Date :
2011-09-05 16:22:49 |
By :
narak0001 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|