2012-01-05 7 views
0

내 서버는 함수가 지원되지 않기 때문에 오류를 계속 반환합니다. 젠드 최적화 도구가 PHP 5.3을 지원할 때까지 PHP 5.3으로 업그레이드 할 수 없다는 것을 최근에 알아 냈습니다. 현재 서버 관리자는 서버 환경에 대한 ZO의 안정 버전을 고수하고 싶습니다.PHP 5.3에서 PHP 5.2.17에 맞게 조정 된 코드

코드를 조정할 것을 권장 할 수 있습니까?

Fatal error: Call to undefined method DateTime::createfromformat() 

코드입니다 :

$today = date('l'); 

    if($today == 'Wednesday'){ 
     $min = date('d/m/Y', strtotime('0 days')); 
     $max = date('d/m/Y', strtotime('+6 days')); 
    }else if($today == 'Thursday'){ 
     $min = date('d/m/Y', strtotime('-1 days')); 
     $max = date('d/m/Y', strtotime('+5 days')); 
    }else if($today == 'Friday'){ 
     $min = date('d/m/Y', strtotime('-2 days')); 
     $max = date('d/m/Y', strtotime('+4 days')); 
    }else if($today == 'Saturday'){ 
     $min = date('d/m/Y', strtotime('-3 days')); 
     $max = date('d/m/Y', strtotime('+3 days')); 
    }else if($today == 'Sunday'){ 
     $min = date('d/m/Y', strtotime('-4 days')); 
     $max = date('d/m/Y', strtotime('+2 days')); 
    }else if($today == 'Monday'){ 
     $min = date('d/m/Y', strtotime('-5 days')); 
     $max = date('d/m/Y', strtotime('+1 days')); 
    }else if($today == 'Tuesday'){ 
     $min = date('d/m/Y', strtotime('-6 days')); 
     $max = date('d/m/Y', strtotime('0 days')); 
    } 

    // check database for necessary updates 

$update = mysql_query("SELECT * FROM rent WHERE colour='#3C0'"); 
while($row_update = mysql_fetch_array($update)) { 
    $datetime_lower = DateTime::createFromFormat('d/m/Y', $min); 
    $datetime_upper = DateTime::createFromFormat('d/m/Y', $max); 
    $datetime_compare = DateTime::createFromFormat('d/m/Y g:i a', $row_update['pDate']); 
    if ($datetime_lower < $datetime_compare && $datetime_upper > $datetime_compare) { 
     // date is between do nothing 
    } else { 
     // date is not between so update 
     $update_result = mysql_query("UPDATE rent SET colour='#F0F0F0' WHERE id=" . $row_update['id'] . " && colour='#3C0'"); 
     mysql_close($update_result); 
    } 
} 

나는이 문제를 어떻게 해결할 수 있습니까?

+0

PHP 5.3이 안정이와/ELSEIF 블록의 경우. –

+0

@cillosis Zend Optimizer에서 지원하지 않기 때문에 서버 관리자는 PHP 5.3으로 업그레이드 할 수 없습니다. – methuselah

답변

0

DateTime::createFromFormat('d/m/Y', $xxx);date('d/m/Y', strtotime($xxx));으로 바꾸십시오.

+0

'date ('d/m/Y', strtotime ($ xxx)); ' –

0

PHP < = 5.3가 더 이상 그래서 업그레이드에 대한 귀하의 관리자를 convice하려고합니까, 지원 (- 안정적인 젠드 최적화 또는 안정적인 PHP 인터프리터 - 그들이 선택할 수 없습니다? 더 중요하다)

+0

Stable! = supported. 그들은 업그레이 드해야하지만, PHP는 5.2.17 안정도 –

+0

긴 theres 아니 0 일 감지 ... –

2

당신은 그 큰를 대체 할 수 다음 SQL 루프에서 아래

$today = date("w"); 
$min_mod = ($today < 3) ? -4 - $today : 3 - $today; 
$max_mod = ($today < 3) ? 2 - $today : 9 - $today; 
$min = strtotime("today 00:00:00 -".$min_mod." days"); 
$max = strtotime("today 23:59:59 +".$max_mod." days"); 

:

//$datetime_lower = DateTime::createFromFormat('d/m/Y', $min); 
//$datetime_upper = DateTime::createFromFormat('d/m/Y', $max); 
$compare = strtotime($row_update['pDate']); 
if ($min < $compare && $max > $compare) { 
    // date is between do nothing 
} else { 
    // code snipped 
}