I am working on a database project and having a problem. In order for my relations to be in BCNF I have attributes spread across many tables. So adding a user will require updates to many tables. The problem I am having is that suppose this happens:
Add info to table A
Add info to table B - Oops, can't add so I need to remove entry from table A
I thought I could do this using exceptions, but apparently the server I am using doesn't allow them (all other PHP has worked). For instance, my own Apache server on my machine executes this text as expected:
<?php
try {
$error = 'Always throw this error';
throw new Exception($error);
// Code following an exception is not executed.
echo 'Never executed';
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
// Continue execution
echo 'Hello World';
?>
but the server I have to use (school project) won't execute it. I get a blank page where I should get exception thrown information.
The algorithm I was hoping to use via exceptions was this:
try
{
/* Performing SQL query */
$query = "INSERT INTO XXXX ";
$result = mysql_query($query);
if (!$result)
{
throw new Exception("ERROR");
}
}
catch (Exception $e)
{
$query = "DELETE * FROM XXX";
$result = mysql_query($query);
die('<BR>There was a problem with inserting. Please try again. ');
}
I was hoping that this would allow me to clean up the mess I made in order to keep my database atomic. Does anyone have any ideas how I can work around this? Thanks!