Locking a Single Row in MyISAM Table
In MySQL, MyISAM tables do not support row-level locking. However, if you require row-level locking capabilities, you can consider switching to InnoDB, which provides this feature.
Switching to InnoDB for Row-Level Locking
To enable row-level locking, you need to convert your user table from MyISAM to InnoDB. You can do this using the following command:
ALTER TABLE <user_table> ENGINE=InnoDB;
Once you have converted to InnoDB, you can use the SELECT ... FOR UPDATE statement to obtain an exclusive lock on a particular row. This will prevent other sessions from modifying or accessing the locked row until the lock is released.
Here's an example:
SELECT * FROM <user_table> WHERE <condition> FOR UPDATE;
Note: You should release the lock promptly after you have completed your operations on the row. This can be done by issuing a COMMIT or ROLLBACK statement.
Additional Resources:
The above is the detailed content of How to Achieve Row-Level Locking in MySQL\'s MyISAM Tables?. For more information, please follow other related articles on the PHP Chinese website!