开发者

mySQL - Apply a row level lock using mysqli

Using PHP'开发者_Python百科s mysqli how do you apply a row level lock?

Row level locks stop anyone editing currently present rows that match your criteria right? but do they stop a user inserting a row which matches your criteria?

Thanks


if you want to lock a specific row from editing, use FOR UPDATE at the end of a SELECT query. this locks the row in your transaction and prevents other users from updating it. this only works in transactional storage engines like innodb.

in answer to your questions, yes, row level locks "stop anyone editing currently present rows that match your criteria". more specifically, if (inside a transaction) you INSERT, UPDATE or DELETE a row, that row is locked from editing by anyone else until your COMMIT your transaction. if you SELECT a row using FOR UPDATE then that also locks the row.

however, this does not "stop a user inserting a row which matches your criteria".


What is it you're trying to achieve? The InnoDB engine uses row level locking but this is an automatic internal MySQL process.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜