tags:

views:

61

answers:

2

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.

A: 

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

Centurion
A: 

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
konforce