Well, I made this great little application that writes to and updates a table in MySQL, but now I have more than one user making updates, and while I feel that the chance of a corruption is slim, I want to be able to lock the table for all other users(threads), write the information to the DB, then unlock the tables.
I am using DBD::mysql. Below is an sample of the code I used to write to the DB:
my $sth = $dbh->prepare("$SQLCommand") or err_trap("Cannot prepare the + load_category_names query"); $sth->execute or err_trap("Cannot execute the SQL query to SQL COMMAND +");
Simple stuff! Yet if I copy these lines above and use LOCK TABLES table read, I cannot write as I am locking all data.
I understand I have a two part issue here:
1) proper perl syntax to write to the database three times
a. lock tables
b. execute my sql command
c. unlock talbes
2) Determining the proper syntax of the lock and unlock to get me where I need to be.
For Perl, do I just copy the two lines of code, replace $SQLCommand with appropriate lock statement. Use the same two lines of code to write my SQLCommand. Then, use the same two lines of code replacing $SQLCommand again with UNLOCK TABLES?
Also if any one has some sample SQL lines on locking procedures *I know this is not a MySQ site, but what the heck, it is related. Thanks folks.
Edited: Sun Oct 14 07:11:57 2001, footpad - Added/Corrected <P> tags and removed repeated paragraphs.
In reply to LOCK TABLES using Perl in MySQL by sdyates
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |