Lock a MySQL table in PHP

If you do a select or insert query against the testTable while it is locked by the script below, the select or insert query will hanging there and execute only after this script released the lock

ini_set('display_errors', 1);

mysqli_query($con,"LOCK TABLES testTable WRITE;");

//Do something or sleep for 30 seconds, no other users can access this table

mysqli_query($con, "UNLOCK TABLES;");


Search within Codexpedia

Custom Search

Search the entire web

Custom Search