Karthik
Karthik

Reputation: 2581

PDO begintransaction vs MySQL db lock

what is the advantage of using pdo begintransaction, is this and mysql db lock are same?

I have a table with urls and status column, whenever my application loads 10 urls I need to update the status column as loaded. This application will be accessed by couple of users simultaneously, how would I prevent user B from loading the same urls loaded by user A and before the update of the status column.

Please could anyone help me.

Upvotes: 2

Views: 816

Answers (2)

Matthew
Matthew

Reputation: 48304

Transactions and table locks do different things. In your case, probably the easiest way to accomplish what you want is:

  • Lock the table for writing
  • Select 10 URLs where status = new
  • Set those 10 URLs to be status = processing
  • Unlock the table
  • For each URL, process, and set status = done

Upvotes: 1

Centurion
Centurion

Reputation: 5291

PDO::beginTransaction will make possible to rollbak changes if something went wrong with PDO::rollback, while lock tables will not.

Upvotes: 1

Related Questions