How to make something expire after certain months in db?

Asked

Viewed 152 times

-2

I want to add a "license" for a purchase in my database, plus this license that my "customer" will buy will have an expiration date, let’s say he bought a license...

    INSERT INTO compras (userid, pluginid) VALUES ('$userid', '$pluginid');

Now, I want to make this INSERT that I did go out in a month, for example, how do I do this??

2 answers

3

2


Do not do this deletion, create a DATA_DE_VALIDADE column , in the application test something like

select *
from compras
where userid = 'DaviDEV'
and   CURDATE() <= DATA_DE_VALIDADE

The advantage is not to lose the information allowing to "run after" the customer for a return.

  • More at INSERT time, which I fill in the field DATA_DE_VALIDADE?

  • Something like ADDDATE(CURDATE(), INTERVAL 31 DAY), ie the date when "expires" the purchase. In the case 31 days of the current date.

  • Type: INSERT INTO purchases (userid, pluginid,expiration) VALUES ('$userid', '$pluginid',ADDDATE(CURDATE(), INTERVAL 31 DAY)); ??????

  • Yes, but the column needs to exist in the table, for this see ADD COLUMN emhttp://dev.mysql.com/doc/refman/5.7/en/alter-table.html

  • I think Motta’s suggestion is better, never discard a customer’s purchase history. even because, if your system happens to provide the same license number of a customer who has already purchased it, you may get complicated

  • No, I’m just using it to absorb knowledge, I don’t have a web shop or anything like that.

  • then just think of it as good practice!

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.