Connecting Tech Pros Worldwide Help | Site Map

Lock Problem

archulu's Avatar
Member
 
Join Date: Mar 2007
Posts: 34
#1: Aug 22 '07
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's Avatar
Member
 
Join Date: Mar 2007
Posts: 34
#2: Aug 24 '07

re: Lock Problem


this is answer for question



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

my $sth2=$dbh->prepare("UPDATE 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($update,$already);

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

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

$sth1->finish;
$sth2->finish;
$dbh->disconnect;
Reply


Similar PostgreSQL Database bytes