Create CSV automatically in PHP

1

I have a function that creates a .csv file with data from the database and I wanted it to be generated automatically and saved in a project folder. The thing is that I can not find anywhere how it is generated automatically, the function works correctly, I just need that. Thank you very much!

    
asked by Csc99 25.07.2018 в 17:27
source

2 answers

1

Create a scheduled task and load a .bat file that contains the php path you want to run.

START "" "C:\ventas.php" o START iexplore.exe http://localhost/archivo.php 

Create a text file and save it with the .bat extension

    
answered by 25.07.2018 / 18:45
source
3

If you use Linux, use a cronjob.

  • Check if you have cron installed, perhaps using a man cron or a sudo apt list --installed | grep cron - it is usually installed in each linux distribution -, if not installed, install it with sudo apt install cron .

  • Create a cronjob as follows:

    crontab -e
    

    and it will ask you to choose the text editor with which you want to write your cronjob. After choosing your text editor, you will have to put the frequency of execution of your program followed by your program in the cron file, something like this:

    * 18 * * *  php /ruta/a/tu/programa.php
    

    and "programa.php" will run every day at 6 o'clock in the afternoon of your time zone.

  • For more information about cronjobs see man 8 cron , man 1 crontab and / or man 5 crontab

    Crontab allows you to execute tasks by frequency, something like this:

    minutes hours days months dias_de_la_semana your_program with the * * * * * program format, that you can check in man 5 crontab

    If you want help with the frequency, you can use this page: link

        
    answered by 25.07.2018 в 19:12