0

我的服务器不断返回错误,因为该功能不受支持。我最近发现在 Zend Optimizer 支持之前我无法升级到 PHP 5.3;目前,我们的服务器管理员希望在服务器环境中坚持使用 ZO 的稳定版本。

您能推荐我可以对代码进行的任何调整吗?

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);
    }
}

我该如何解决这个问题?

4

3 回答 3

2

你可以用这个替换那个大的 if/elseif 块:

$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");

然后在你的SQL循环下面:

//$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
}
于 2012-01-05T22:21:38.823 回答
0

尝试替换DateTime::createFromFormat('d/m/Y', $xxx);date('d/m/Y', strtotime($xxx));.

于 2012-01-05T21:21:47.140 回答
0

不再支持 PHP <= 5.3,所以请尝试说服您的管理员进行升级(让他们选择 - 稳定的 Zend Optimizer 或稳定的 PHP Interpreter - 哪个更关键?)

于 2012-01-05T21:35:40.287 回答