1

I want a functionality that insert data every month...

I have some idea to implement this that is as follow....

When User Create 'INVOICE' at that time the 'INVOICE' automatically generated every next month once user create it.

Let have some code...

INSERT INTO INVOICE (id,user,date,bill_money) VALUES ('','XYZ','25/03/2015','100');

this one works very well now every next month same entry should be automatically inserted..

For that i have logic that when user log-in into portal at that time first i have retrieve user's last log-in and from that date to currently log-in date i try to insert those data which are 30 days old data...

I select next day(date) after user's last log-in date and then Check for every that up to current day(date).

To retrieve user last log-in date

echo $this->session->userdata('name')

To check interval lastlogindate() + INTERVAL 30 DAY == NOW() If this becomes true then then insert data

But here problem is that i want to implement for month, quater, year Is this flow is better or there can be another way to do this..??

I heard about cron job and MySQL Event which one is best in this two and how they are working which one is effective performance wise...

I want suggestion on this. Thank you....

Sagar Naliyapara
  • 3,971
  • 5
  • 41
  • 61

2 Answers2

1

If you want a recurring invoice. Just store the invoice once and schedule a cron job that will run daily at scheduled time. Cron job will run your php script to do whatever you want to do like : store invoice in db or email it to user. If you don't know about cron jobs, basics can be found in this answer : How to create cron job using PHP?

EDIT : you will have to schedule cron job using cli

Community
  • 1
  • 1
Spike
  • 61
  • 5
0

Mysql events

I think this is better for me i haven't use Cron Job...

for Mysql event checkout syntax and have a fun...

Sagar Naliyapara
  • 3,971
  • 5
  • 41
  • 61