Lock Problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • archulu
    New Member
    • Mar 2007
    • 34

    Lock Problem

    hai
    i want to use lock function in my project to lock the database table when i am pressing a button in front_end. at simultaniouly (online) another one press the button the request wait untill that table was unlock.

    plz help to me
    to solve this problem it was very urgent
  • archulu
    New Member
    • Mar 2007
    • 34

    #2
    this is answer for question



    my $sth1=$dbh->prepare("selec t no from max_no") or warn "Erron in prepare statemt ".$dbh->errstr;

    my $sth2=$dbh->prepare("UPDAT E max_no SET no = ? where no = ?") or warn "Erron in prepare statemt ".$dbh->errstr;

    my $lock = $dbh->do("lock table max_no in share row exclusive mode");


    $dbh->begin_work;
    my $err=$sth1->execute();
    @n2=$sth1->fetchrow_array ();


    $already=$n2[0];

    $update=$n2[0];
    $update++;

    if($update == 1000 ) {
    $update = 1;
    }

    my $err;

    eval {
    $err=$sth2->execute($updat e,$already);

    };
    if($@)
    {
    $dbh->rollback;
    }
    else {
    $dbh->commit;
    }

    if($err != 1) {
    $err = 2;
    }

    $sth1->finish;
    $sth2->finish;
    $dbh->disconnect;
    Last edited by archulu; Aug 24 '07, 01:42 PM. Reason: add information

    Comment

    Working...