db_lock_table

5 database.mysqli.inc db_lock_table($table)
5 database.pgsql.inc db_lock_table($table)
5 database.mysql.inc db_lock_table($table)
6 database.pgsql.inc db_lock_table($table)
6 database.mysqli.inc db_lock_table($table)
6 database.mysql.inc db_lock_table($table)

Lock a table.

Related topics

File

includes/database.mysql.inc, line 335
Database interface code for MySQL database servers.

Code

function db_lock_table($table) {
  db_query('LOCK TABLES {' . db_escape_table($table) . '} WRITE');
}

Comments

Multiple table locks

db_lock_table() will only lock one table at a time. If you need a lock while accessing multiple tables, or if you use table aliases, use a LOCK TABLES statement through db_query() instead. Bear in mind that this will make your code MySQL dependent so should be considered a last resort for specific concurrency problems.

From the MySQL documentation:

A session that requires locks must acquire all the locks that it needs in a single LOCK TABLES statement. While the locks thus obtained are held, the session can access only the locked tables.

If your statements refer to a table by means of an alias, you must lock the table using that same alias. It does not work to lock the table without specifying the alias...

Login or register to post comments