Cron Job(PHP) - >选择明年的记录不起作用

时间:2017-12-27 12:08:13

标签: php mysql cron

ID  | Client  |    Data    | Hosting   | Price |
    |         |            |           |       |
    |         | 2018-01-02 | Heineken  | 500   |
    |         | 2018-01-03 | Hestia    | 200   |
    |         | 2017-12-28 | Bravo     | 200   |
    |         | 0000-00-00 |           |       |
    |         | 0000-00-00 |           |       |

为什么我希望PHP代码从明年 2018-01-03 中选择明年的记录(2017-12-27) strong>我的代码没有返回任何匹配的记录(即使有这个日期的记录)?这是我的粉丝代码:

<?php

    use PHPMailer\PHPMailer\PHPMailer;
    include_once "PHPMailer/PHPMailer.php";
    include_once "PHPMailer/Exception.php";

    $mysqli = new mysqli('localhost', 'stdeja_przypomnien', 'admin123', 'stdeja_root');

    $tbl_2 = $mysqli->query( "SELECT * FROM subjects WHERE date(data_waznosci) = CURDATE()+7;");

    if($tbl_2->num_rows == 1) {
        $mail = new PHPMailer();
        foreach($tbl_2 as $email => $details) {        
            $fullname = $details['klient'] . ' ' . $details['data_waznosci'];

            $mail->addAddress('piterdeja@gmail.com');
            $mail->setFrom('system_przypomnien_hosting@powiadomienia.pl');
            $mail->Subject = "Hosting - system przypomnień";
            $mail->isHTML(true);
            $mail->Body = "W dniu {$details['data_waznosci']} kończy się hosting klientowi {$details['klient']} na KWOTĘ {$details['cena']}, hosting to {$details['Hosting']}";

            if ($mail->send())
                echo "Formularz został wysłany. Postaramy się odpowiedzieć jak najszybciej.";
            else
                echo 'Mailer Error: ' . $mail->ErrorInfo;
        }             


}  
?>

令人惊讶的是,当我选择明天的日期2017-12-28时,代码为:CURDATE()+ 1选择 DOES work (返回匹配记录'Bravo');

1 个答案:

答案 0 :(得分:0)

尝试使用date_add()

$tbl_2 = $mysqli->query( "SELECT * FROM subjects 
      WHERE date(data_waznosci) = date_add(CURDATE(), INTERVAL 7 DAY);");