Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Mysql snapshot on button click
  • I am trying to enable mysql db to be downloaded as a snapshot on the click of a button. My folder structure is as follows:

    app/controller

    -- export (subcontroller)
    ----- login.php
    -----snapshots.php

    app/views

    -- export (nested view)
    -----login.php
    -----snapshots.php

    routes.php

    'export'                                            =>  'export/snapshots/view'
    'export/login'                                    =>  'export/login/login'
    'export/logout'                                  => 'export/login/logout'

    'export/snapshots/download'           => 'export/snapshots/download
    'export/(:segment)s/(:num)'              =>  'export/$1/view/$2

    The db needs to be downloaded every 3 months and every 6 months. While I can successfully login the snapshots page is displaying error 404. I am pretty sure the db download function should be in controller but I would like to know how to proceed with enabling user to download snapshots of the entire database.

    Thanks in advance
  • I can't comment on why you get a 404, you'll have to debug that.

    As to downloading a database snapshots, that is a very ambiguous task. What is the purpose of this download, what will happen with the data after the download? In which format are you going to download it?
  • I believe the 404 is due to not having the correct controller code in place therefore cannot see the view properly. Once the user logs in, they should be presented with the download button below:





    Once clicked, the user should be able to download snapshot of the entire db as a file (in a folder) on the user's local machine (they would like to keep a snapshot of the db record rather than altering the original db). They should be able to take snapshots of data entered quarterly (at 3 months and 6 months). Also, they want to be able to download snapshot of data entered on the day.

    However, the user is not quite tech savvy and would like the easiest way to access the snapshots so I am open to suggestions for a simpler solution. Also, since controller is the one handling the request I don' t think I would require a model, would I?

    Thank you

  • Client requirements:

    Would it be possible to programme so that the SQL file is created and archived automatically every 3 months, whereas the user-file could be generated by me as needed on my PC?
  • So a snapshot is a file with SQL commands? Like a PHPMyAdmin export?

    If you have cron access to that server, it's probably easier to schedule a nightly "mysqldump", so that file can be downloaded, instead of trying to generate a SQL dump (which will take very long if done in a controller).

    The controller problem is for you to solve, it's impossible to comment without acccess to the code (which I don't want ;-)).
  • Similar to PHPMyAdmin export but using Toad for MySQL instead.

    However, since I do not have cron access and as you said the mysqldump will take quite a while, the simplest format I currently came across was downloading the data in each sql table as a html table in a single zip file. This would allow the user to download the zip file containing the html table with the data from the database whenever needed.

    Would that be a better alternative? Since the sql query will generate the table, I am going to be writing the query in the controller and allowing the user to download the generated zip file via a download button.

    Thanks in advance
  • If you need to dump (and possibly restore) in PHP code, you might want to look at an old project of mine that has a similar feature: https://github.com/ExiteCMS/ExiteCMS7/blob/master/administration/db_backup.php

    Note that this code originated in PHP 4, so please don't copy and paste ! It should however give you some pointers. 

  • Thanks for getting back to me.

    Also, thank you for both links it should be helpful and don't worry I won't copy and paste ;)


Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion