By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 1,086 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

Lock Problem

archulu
P: 34
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
Aug 22 '07 #1
Share this Question
Share on Google+
1 Reply


archulu
P: 34
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;
Aug 24 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.