简体   繁体   中英

Creating a PHP CMS with an entry backup/restore option

I've been working on a CMS and wanted to add a backup/restore function. I want it to backup a saved entry every other time it is edited so that if a client makes a change they are unhappy with or screws something up they can go back and choose a previous state to restore from.

The problem I'm having is trying to wrap my head around the concept of coding this functionality. I have created a new table called "backup" with the fields "ID, date, time, pageName, and pageContent" but going on from there I find myself stuck.

Would I add on to my edit script a new query that saves a duplicate to the backup table? And how could I get it to only backup every few saved edits?

Here I have my save edit query, if it helps any. Thanks in advance! :)

<?php
        $_POST['entry'] = mysql_real_escape_string($_POST['entry']);
        $sql="update pageEntry set entry=\"$_POST[entry]\", pageName=\"$_POST[pageName]\" where id=\"$_POST[id]\"";       
        $result=mysql_query($sql)or die('Bad Query');
            echo "<div id='edit2'>The file has been uploaded, and your information has been added to the directory<br /></div>";  
?>

Version control at the table level is usually done by adding a version column to your existing table. So if you had a posts table you would add a version column with a simple int or date value. Every time a post is edited a new record is inserted and the version number bumped. You can reference this version number in another table or have an additional active field to denote which post is the latest/active.

If you're talking about rolling back the database I would use the mysqldump command to dump and mysql to restore.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM