When developing a project, you may encounter a problem: You must Randomly Read some records of a table and set update to unreadable, multiple people may randomly perform the same record at the same time and perform the update operation again, causing dirty Data Reading and repeated operations,
Therefore, consider locking the table. However, MyISAM is used, and transactions are not supported. Only table-level locks can be applied, and other users do not have the read permission. The following are two test files that run test in Firefox. PHP: Run test1.php in IE, and you will find that, within 10 seconds after Firefox runs, ie is in the waiting status, which is actually test. PHP locks the table, the webpage is not running, and the lock is not released. After 10 seconds, the lock is automatically released, and content is immediately displayed in IE, in this way, the records of the table are read and modified randomly, but the disadvantage is that other processes do not have the permission to read the table during the table lock, that is, when you operate a table record, the Administrator does not have the read permission. You still have to modify the table engine to InnoDB and use transactions to solve the problem.
Test1.php
$ Db = new dB (); <br/> $ db-> locktable ("lock tables sbs_temp write "); <br/> $ SQL = "select * From sbs_temp limit 5"; <br/> $ rs = $ db-> getrs ($ SQL ); <br/> foreach ($ RS as $ row) {<br/> echo $ row ['query']. "<br>"; <br/>}</P> <p>
Test. php
$ Db = new dB (); <br/> $ db-> locktable ("lock tables sbs_temp write "); <br/> $ SQL = "select * From sbs_temp limit 5"; <br/> $ rs = $ db-> getrs ($ SQL ); <br/> foreach ($ RS as $ row) {<br/> echo $ row ['query']. "<br>"; <br/>}< br/> sleep (10); <br/>