PHP, mysqli, and table locks? -


I have a database table where I want to draw a line, to test the user input to match, then to identify Update the line for the user should have a race condition created by the match, I need to make sure that the user's update was not overwritten by any other user.

I intend to accomplish this:
1. Read the row 2. Lock table. 3. Read the row again and compare it with the original line 4. If the update updates in the rows If otherwise, nothing else (other user has already updated the row)

Based on the information found on Google, I was expecting a lock table statement until the lock was checked . I have set up a small test script in PHP which will stall for 10 seconds and allow me time to manually create a race condition.

  // Wikipedia number $ aData ["round_id"] = $ Database ["round_id"]; // To perform a selection on routine database (ommited for brevity) $ aRound = $ oRound-> getInfo ($ aData); "Early rounded data echo": "; print_r (around $); echo" locking ... "; echo $ oRound-> lock (); echo" is going to allow for conflict ... "; $ ($ ARound ["victor_nation"] == $ aLockedRound ["victor_nation"]); $ $ [$ aData], "sleep", "sleep", "awake ..."; $ alockedRound = $ oRound-> getInfo Victor_nation "= $ aRound [" victor_nation "] + 1; $ ORound-> Update ($ ADATA);" Enhanced Victor Nation "echo;}  

Where the lock routine

  function lock () {global $ oDatabase; $ IReturn = 0; // table $ iReturn = $ oDatabase-> m_oConnection-> Lock the query ("Write the lock table round"); return $ iRe Turn;}  

above, $ oDatabase-> m_oConnection is a mysqli connection that I use to execute a prepared statement on the database.

When I run my test script, I close the user first and wait for "Stowling ... to allow for conflict" and then start another script. Were expected to stop "locking ...", however, the second scrip T continues Stoling to allow for the "struggle".

Since LOCK does not make the statement appear to be blocked, or does not return any pointer to the lock (return value is echo and empty), it is not clear to me that I actually Even though I'm getting the lock, I'm not sure how to move forward.

Any hint? Troubleshooting: Testing for table lock success by trying to work with any other table, you can get it done by using a different table.

Which can not be locked. If you have received a lock, then trying to write on a table that is not included in that lock statement should cause an error.

You may want to consider an alternative solution. Instead of locking, to make an update, which contains the converted element as part of the segment, if the data is changed if you change it, then the update will be "failed" and zero rows will be modified. This eliminates the table lock, and all the messs that can come with it, including the deadlock.


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -