You are looking for LOCK.
http://dev.mysql.com/doc/refman/5.0/en/lock-tables.html
This can be run as simple mysql_query(or MySQLi::query/prepare).
I would say that it is better to block certain tables (although you can probably try LOCK TABLES *) that you need to block, rather than the entire database - since nothing can be read. I think you are looking for something like:
LOCK TABLES items;
START TRANSACTION;
INSERT INTO items (name, label) VALUES ('foo', 'bar');
UNLOCK TABLES;
Or in PHP:
mysql_query('LOCK TABLES items');
mysql_query("INSERT INTO items (name, label) VALUES ('foo', 'bar')");
mysql_query('UNLOCK TABLES');
source
share