Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

How do I lock tables using DBI and mySQL?

by filmo (Scribe)
on Sep 11, 2001 at 08:41 UTC ( [id://111666]=perlquestion: print w/replies, xml ) Need Help??

filmo has asked for the wisdom of the Perl Monks concerning the following question: (database programming)

How do I lock tables using DBI and mySQL?

Originally posted as a Categorized Question.

  • Comment on How do I lock tables using DBI and mySQL?

Replies are listed 'Best First'.
Re: How do I lock tables using DBI and mySQL?
by blakem (Monsignor) on Sep 11, 2001 at 08:51 UTC
    See the Lock Tables syntax in the MySQL documentation. Then wrap each sql query inside of something like:
    $dbh->do(" ... ");
Re: How do I lock tables using DBI and mySQL?
by filmo (Scribe) on Sep 11, 2001 at 09:01 UTC
    Follow up question: Does the lock cover multiple statement handles? i.e.
    $dbh->do("LOCK TABLES foo WRITE, bar READ"); $sth->prepare("SELECT x,y,z FROM bar"); $sth2->prepare("INSERT INTO foo SET a = ?"); while (@ary = $sth->fetchrow_array()) { $sth2->$execute($ary[0]); } $sth2->finish(); $sth->finish(); $dbh->do("UNLOCK TABLES");
    Is this correct or will $sth2 not be able to access the tables because of the lock?
Re: How do I lock tables using DBI and mySQL?
by blakem (Monsignor) on Sep 11, 2001 at 10:07 UTC
    Yes, I that should work... Table locking is done at the per-thread level, and I think both statement handles above exist within the same thread.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://111666]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2024-04-20 04:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found