我在数据库(mysql)中有负数,是php代码吗?

发布于 2024-09-13 07:09:07 字数 434 浏览 8 评论 0原文

描述:

我正在做购买功能,每当用户购买时,就会为我的网站特殊页面添加1个月的访问权限。我收到了一些用户的投诉,请阅读问题部分。

问题:

500个用户中,有少数用户,例如:今天购买,但到期日向后推,1、2天,甚至几个月。例如:他于2010年8月3日购买,有效期为2010年5月25日。

我的Php代码:

我用来在插入mysql数据库之前添加1个月的代码是:

// I already set the default timezone
$expiryDate = date("Y-m-d H:i:s",strtotime("+1 month"));

我不确定代码是否错误,我的服务器错误或者第三方支付网关错误,请告知如何解决。

!重要问题!

导致有效期倒退的可能原因有哪些?

Description:

I am doing purchasing function, whenever the users make purchases, it will add 1 month privilege to my access special page of my site. I have received some complaints from my users, please read the problem section.

Problem:

Out of 500 users, there are few users, that for example: make purchase today, but the expiration day goes backward, 1 or 2 days, or even months. For example: He purchased on 3 August 2010, the expiration date is 25 May 2010.

My Php code:

The code that I am using to add 1 month before insert into mysql database is:

// I already set the default timezone
$expiryDate = date("Y-m-d H:i:s",strtotime("+1 month"));

I am not sure if its the code is wrong, my server is wrong or the third-party payment gateway is wrong, please advise me how to solve it.

!important question!

What are the possible causes, that can cause the expiration date goes backward?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

笨死的猪 2024-09-20 07:09:07

如果您将到期时间作为日期或日期时间字段存储在数据库中,那么您应该在那里进行更新:

UPDATE table SET expiry=DATE_ADD(expiry, INTERVAL 1 MONTH) WHERE ...;

完整详细信息此处

If you're storing the expiry time in the database as a date or datetime field, then you should do the update there:

UPDATE table SET expiry=DATE_ADD(expiry, INTERVAL 1 MONTH) WHERE ...;

Full details here.

飘然心甜 2024-09-20 07:09:07

使用+1月strtotime存在问题,函数文档页面上有一些解决方案。但是,如果我是你,我会使用像 Zend_Date 这样经过测试的库。您可以按照建议使用 sql,但我猜这将偏离您组织数据库特定代码的方式。

There are issues using +1 month with strtotime, there are some solutions on the function document page. However if i were you i would use a tested library like Zend_Date. You could use the sql as suggested but im going to guess thats going to depart from how you organized your DB specific code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文