Sets a savepoint within a transaction block.
Savepoints allow you set a point within a transaction to rollback to if a failed condition is met without affecting any work done in the transaction before the savepoint was declared.
bool obj_savepoint ( str name )
True on success or false on failure.
<?php
try
{
$trans = $dbh->obj_transaction();
$data = array( "color" => "blue",
"type" => "leather",
"price" => 36.95 );
$rs = $dbh->obj_update( "products", $data, "prod_id=21" );
if ( $dbh->obj_error() )
{
$trans->obj_rollback();
throw new Exception( $dbh->obj_error_message() );
}
$trans->obj_savepoint( "svp1" );
$data = array( "color" => "red",
"type" => "leather",
"price" => 32.95 );
$rs = $dbh->obj_update( "products", $data, "prod_id=49" );
if ( $dbh->obj_error() )
{
$trans->obj_rollback( "svp1" );
$trans->obj_commit();
throw new Exception( $dbh->obj_error_message() );
}
else
$trans->obj_commit();
}
catch ( Exception $e )
{
//log error and/or redirect user to error page
}
?>
See also: obj_rollback, obj_savepoint