Friday 15 May 2015

mysql - PHP PDO fetch behaviour -


Assume that the table has many records in the table table and I ask a selection statement with some conditions In this situation, after receiving the record foo = 1 , I will use this record to do something that spends so much time, and I have to understand it easily sleep (2) .

  $ Stmt = $ dbh- & gt; Query ('SELECT * FROM table WHEER foo = 1'); While ($ line = $ stemat-> fetch (PDO: FETCH_ASSOC)) {// Slow sleep (2); }  

After receiving the first line , if there is any other session to update the table, for example, the third line Update (let's assume the original foo 1) and set foo = 0, will the above script still retrieve the third line ? I wonder what the fetch function does behind the code. Generally, when you execute a query, it runs until it is complete, the results are sent to your database driver, in this case PDO, for consumption.

Even when you are using techniques to sequentially obtain data, such as cursor or streaming rosets, the effect is similar: the result of your query is affected by the subsequent statements Will not done.

Consider taking a snapshot of all the items received from the PDO at a singular point.


No comments:

Post a Comment