To Delete, or not to Delete
April 21st, 2008 | by admin | |Another possibly interesting aspect of my CMS is that I never actually ‘delete’ anything. I simply hide the content with the smart use of a recordstatus field. When information in the ’seen’ system is deleted, it is not actually gone, it is simply hidden from view. The information remains in tact in my database.
An example of how I manage this is as follows:
/*
* @summary: Delete a single database record, based on id
* @param: id of record to select
*/
function db_delete($id) {
connect_to_database();
$id = set_safe_data($id);
//create query
$sql = "UPDATE template ";
$sql .= " SET recordstatus = 'D' ";
$sql .= " WHERE id = '$id' ";
$sql .= " LIMIT 1 ";
//execute query
mysql_query($sql);
if(mysql_error() != '') {
process_sql_error('db_delete:'.mysql_error());
exit;
}
} // end function
Why do I do this? I made the mistake in an early version of my CMS (which DID actually delete) when I was browsing my records. I had just written a piece on PHP Classes. The article had taken me over an hour to write. At the time I had also been adding delete confirmation to my delete buttons and I wanted to see what it looked like, so I pressed the delete button. … No delete confirmation came up and my PHP Class article was deleted. Needless to say I’m sure the neighbours heard a few loud curses at that precise moment in time
Gone with no chance of recovery, as I had no recent database backups (which btw you SHOULD have in place, either weekly or at least monthly).
So from then on I made a rule to myself to switch to the recordstatus variable of hiding information. If I’d been stupid enough to make the delete mistake with important data, others would too. So as an administrator of my CMS, I need to be able to help my members if they come to me saying ‘HELP I deleted something I didn’t mean to!’. I suggest you make the same change where possible, it will save you much grief ![]()