Hi
It 'is correct the way in wich i had implemented this transaction?
try{
autocommit($conn,false);
$sql = "Select MaxOfferta from offerta where IdObj= '". $id . "'";
if(!$res=@mysqli_query($conn,$sql))
{
throw new Exception ( "Errore durante accesso db <br> Attenzione: fra 10 secondi sarai reindirizzato");
}
$r=mysqli_fetch_array($res,MYSQLI_ASSOC);
if ( $r["MaxOfferta"]<$offerta ) {
$sql = "Update offerta set MaxOfferta='".$offerta."' ,UserOfferente='".$_SESSION["s211566username"]."' where IdObj= '". $id . "'";
if(!$res=@mysqli_query($conn,$sql)){
throw new Exception ( "Errore durante accesso db <br> Attenzione: fra 10 secondi sarai reindirizzato");
}else{
$ref = $_SERVER['HTTP_REFERER'];
header( 'refresh: 10; url='.$ref);
echo "Offerta accettata <br> Attenzione: fra 10 secondi sarai reindirizzato";
}
}else{
echo "Offerta troppo bassa,Rilancia almeno di 10 centesimi <br> Attenzione: fra 10 secondi sarai reindirizzato";
$ref = $_SERVER['HTTP_REFERER'];
header( 'refresh: 10; url='.$ref);
}
mysqli_commit($conn);
mysqli_close($conn);
}catch(Exception $e) {
mysqli_rollback($conn);
echo "Rollback della transazione ". e->getMessage();
$ref = $_SERVER['HTTP_REFERER'];
header( 'refresh: 10; url='.$ref);
mysqli_close($conn);
}
Is a very simple example of auction, i wanna guarantee that
if a read something before it write the new offer no one can read the db.
Thanks in advance.