我在数据库(mysql)中有负数,是php代码吗?
描述:
我正在做购买功能,每当用户购买时,就会为我的网站特殊页面添加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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您将到期时间作为日期或日期时间字段存储在数据库中,那么您应该在那里进行更新:
完整详细信息此处。
If you're storing the expiry time in the database as a date or datetime field, then you should do the update there:
Full details here.
使用
+1月
和strtotime
存在问题,函数文档页面上有一些解决方案。但是,如果我是你,我会使用像 Zend_Date 这样经过测试的库。您可以按照建议使用 sql,但我猜这将偏离您组织数据库特定代码的方式。There are issues using
+1 month
withstrtotime
, 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.