7

我有一个自动检查器,用于检查将在接下来的 7 天内到期的域,并将其发送并通过电子邮件发送给客户。

我使用这个 SQL 查询:

 $sql="SELECT * from domain_names where (status = '' or status = 'valid') and date(expiry_date) = date(now() + interval 7 day) ";

它工作正常,但如果它停止运行并且一天过去了,它不会做它错过的域。什么是让它做它错过的领域的最好方法?

例如,如果一个域在 7 日到期并且它在 1 日运行,它将看到该域并向客户发送电子邮件,然后在行上放置一个标志,表示电子邮件已经发送,但如果检查器在 1 日没有运行并且它2 日再次开始运行它不会看到该域(行)

4

13 回答 13

1

Just a little modification in the code of yours(Putting '<'):

$sql="SELECT * from domain_names where (status = '' or status = 'valid') and date(expiry_date) <= date(now() + interval 7 day) ";
于 2014-07-08T06:39:48.547 回答
0

You are only checking for days exactly 7 days ahead. You want to check for up to 7 days ahead. Change your code to:

$sql="SELECT * from domain_names where (status = '' or status = 'valid') and date(expiry_date) <= date(now() + interval 7 day) ";

Since you have a flag any that have already been emailed within this period wont get e-mailed again.

于 2013-06-28T15:42:21.887 回答
0

You want to check where DATE is LESS THAN OR EQUAL TO (today + 7 days).

You should also have some sort of a "flag" in the table, such as reminderSent - so you don't send multiple reminders every time the query/script is ran.

$sql = "SELECT * from domain_names WHERE
  (status = '' or status = 'valid') AND 
  date(expiry_date) <= date(now() + interval 7 day) AND
  AND !reminderSent";
于 2013-06-28T15:42:27.090 回答
0

如果您的虚拟主机提供,请在服务器端设置 CRON 事件。然后,您可以根据需要随时运行它,而不必担心停电或互联网中断。

于 2013-09-03T17:23:34.440 回答
0

试试这个查询。它将为您使用完整的..

$sql="SELECT * from domain_names where (status = '' or status = 'valid') and DATE_ADD(expiry_date, INTERVAL 7 DAY)";

于 2014-03-04T13:10:48.163 回答
0

因为您有一个标志来指示是否已发送电子邮件。只需检查将在未来 7 天内到期的所有域的标记状态。

并且您的查询仅返回从现在起一周到期的域。修改它以返回在未来 7 天内到期的域。

于 2013-06-28T15:42:48.607 回答
0

本质上,如果邮件在 7 天内或有不完整的标志,您需要发送邮件。

但是,我会将列从字符串更改为整数,因为它实际上只有两个值sentnot sent即 1 或 0。

SELECT 
  * 
FROM 
  domain_names 
WHERE 
  status = 0 
OR 
  expiry_date BETWEEN NOW() AND DATE_ADD(NOW(), INTERVAL 7 DAY)

在这种情况下,如果您将状态字段更新为 1,您将始终能够在下次脚本失败时发送。

于 2013-06-28T15:48:17.893 回答
0

也许您需要一些日期间隔,例如:

$sql="SELECT * from domain_names where (status = '' or status = 'valid') and date(expiry_date) between date(now()) and date(now() + interval 7 day)";
于 2013-06-28T15:48:38.490 回答
0

将处理日期添加到记录中。这是双重的,它为您提供了已处理的标志,但它也为您提供了通知发送时间的历史参考。

在您的查询中,添加一个条件,说明 processes_date 为 null,并且 expiry_date 小于或等于今天加上 7 天。

(pseudo) where ...  and processed_date is null and expiry_date <= today + 7

当您在错过后寻找记录时

于 2013-06-28T15:48:59.757 回答
0

或者你可以在 php 中设置它,使用一个变量代替当前日期加上 7 天,例如;

$nextWeek=date("Ymd")+7;
$sql="SELECT * from domain_names where (status = '' or status = 'valid') 
and date(expiry_date) <= $nextWeek) ";

"Ymd"无论您使用什么日期格式,如果不同,您都需要交换,20140621正如我写的那样,这将转换为20140628.

小写m和小写d允许两位数的日期和月份"06""01". 大写我相信会将其更改为个位数....2014621 您可以更改顺序并输入"/""-"如下所示:

日期(“MDY”)+7 = 2014 年 6 月 28 日

日期(“d/M/Y”)+7 = 28/6/2014

于 2014-06-21T14:02:27.503 回答
0

您可以使用此代码。

$sql = SELECT * from domain_names where (status = '' or status = 'valid') and date(expiry_date) = DATE_ADD(date(now()), INTERVAL 7 DAY);

它可能会帮助你...

于 2014-09-24T06:32:34.460 回答
0
This should give the result as you need:

DATE_SUB(CURDATE(),INTERVAL 7 DAY) = expiry_date;
You can refer to the link below for more details:

http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html
于 2013-06-28T15:53:46.537 回答
0

您是否考虑过添加您上次检查到期记录的日志,然后使用该日期作为变量,以便您可以在每次代码运行时从最后一个日期开始检查?

于 2014-10-07T11:29:17.977 回答