开发者

What I have minus months in database (mysql), is it the php code?

开发者 https://www.devze.com 2023-01-10 16:48 出处:网络
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, plea

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 = 开发者_StackOverflow中文版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?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消