Hi
Initially, this was going to be a question about transactions, but perhaps I'm doing the basic INSERTs incorrectly ...
I need to INSERT into 6 tables, if any of these fail, I don't want to write anything.
So, I headed off into the unknown waters of transactions [i'm a front-end developer delving in the dark of back-end work].
However, I kept receiving the following error:
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
In the end, I faked the rollback by just not commiting the data [see below].
Is this way off of what I should be doing ??
Thanks for reading, if you can help, I'd appreciate it.
$commit = TRUE;
if(mssql_query("BEGIN TRAN"))
{
foreach($insert_array as $value)
{
$result = @mssql_query(${$value});
if(!$result)
{
$commit = FALSE;
}
}
if ($commit)
{
mssql_query("COMMIT TRAN");
}
else
{
// mssql_query("ROLLBACK"); // Doesn't work, ignore
echo ("DO SOMETHING TO DEAL WITH THE ERROR");
}
}