Skip to content

Instantly share code, notes, and snippets.

@1stvamp
Created June 22, 2009 09:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 1stvamp/133886 to your computer and use it in GitHub Desktop.
Save 1stvamp/133886 to your computer and use it in GitHub Desktop.
Get a table level lock using PEAR::DB_DataObject
<?php
// How to lock a table using PEAR's DB_DataObject in a semi-OO way,
// note this still relies on the DB-dependant LOCK/UNLOCK syntax,
// change for the relevent RDBMS
// Lock
// You can also specify other options such as READ and the priority below
// see RDBMS docs, in this case MySQL
$object->getDatabaseConnection()->query('LOCK TABLES ' . $object->tableName() . ' WRITE');
// Unlock
$object->getDatabaseConnection()->query('UNLOCK TABLES');
// You could also use the direct ->query() method from $object itself
// above, but I'm not sure if doing this might attempt DB_DataObject to
// coerce data into the instance, as this is normally used for manually
// running a SELECT
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment