Skip to content

Instantly share code, notes, and snippets.

@phpdave
Last active August 28, 2015 02:33
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 phpdave/7383edd195450da3e6df to your computer and use it in GitHub Desktop.
Save phpdave/7383edd195450da3e6df to your computer and use it in GitHub Desktop.
Handling the DB2 record lock exception in PHP when updating a record that has a lock.
<?
try
{
$user="BOB";
$id="2";
$db=new PDO("ReplceW/ConnectionString");
$stmt=$db->prepare("UPDATE `users` SET user=:user WHERE ID =:ID");
$stmt->bindParam(":user",$user);
$stmt->bindParam(":id",$id);
$stmt->execute();
}
catch (Exception $exception)
{
//Lets handle the exception of a record lock
//SQLSTATE[HY000]: General error: -913 [IBM][iSeries Access ODBC Driver][DB2 UDB]SQL0913 - Row or object TABLE in LIB type *FILE in use.
if (strpos($exception->getMessage(),'SQL0913') !== false) {
//There's a file lock do what you want to do to handle this situation
$record->putOnHold();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment