Created
June 22, 2009 09:24
-
-
Save 1stvamp/133886 to your computer and use it in GitHub Desktop.
Get a table level lock using PEAR::DB_DataObject
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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