I'm relatively new to all of this but just about
finished setting up a transaction myself.
I'm doing something like this:
this is in php:( i also have functions set up for
"begin", "rollback" and "committ".
You should also set autocommitt to 0 .
Hope this helps!
Stuart
function run_query($sql)
{
$result = mysql_query($query);
if(!$result)
{
return false;
}else{
return true;
}
}
then:
begin();
$query = "INSERT INTO firsttable.....//first query
$res1 = run_query($query);
$query = "INSERT INTO secondtable...//second query
$res2 = run_query($query);
$query = "INSERT INTO thirdtable....//third query
$res3 = run_query($query);
if($res1 && $res2 && $res3) // If all results are true
{
commit();
echo "your insertions were successful";
}else{
echo mysql_errno($link)." :
".mysql_error($link)."\n";
rollback();
exit;
}
> Hi all,
>
> I'm working with tables stored by the InnoDB engine
> and would like to
> be able to commit only if there are no errors
> generated by a group of
> statements like this.
>
> /* -*- sql -*- */
> SET AUTOCOMMIT=0;
> use db1;
> begin work;
> sql statement 1;
> sql statement 2;
> .
> .
> .
> sql statement n;
>
> At this point I'd like to say, in sql,
> if no errors then
> commit;
> else
> rollback
> end
>
> From what I read in the manual I can do one or the
> other (commit or
> rollback) but there didn't seem to be a way of
> conditionally doing one
> or the other of them.
>
> Thanks in advance,
>
> --
> _\\|//_
> ( O-O )
>
---------------------------o00--(_)--00o------------------------------
> Colm G. Connolly | Tel :
> +353-1-716-2851
> Department of Computer Science | Fax :
> +353-1-269-7262
> University College Dublin (UCD) | Web :
> http://darwin.ucd.ie/
> Belfield, Dublin 4 | MSN :
> [EMAIL PROTECTED]
> �ire / Republic of Ireland |
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:
>
http://lists.mysql.com/[EMAIL PROTECTED]
>
>
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]