Icon edb_lock

Manually locks the current row in a cursor.

Syntax
edb_lock(<CursorHandle>)

<CursorHandle> =

Handle of cursor returned by edb_execute function

Returns
TRUE if successful, and FALSE if there are any errors

Usage
The edb_lock function manually locks the current row in a cursor. Manual locks are different from automatic locks in the following ways:
  • Automatic locks are acquired (automatically) by the engine when calling the edb_insert, edb_update, and edb_delete functions, while manual locks must be handled by the developer via the edb_lock, edb_unlock, and edb_unlockall functions.


  • Manual locks supercede automatic locks, and have a longer lifespan than automatic locks. For example, if you use the edb_lock function to acquire a manual row lock on the current row, and then proceed to update the current row. The manual row lock will still exist after the update is complete. Manual row locks exist until they are manually unlocked with the edb_unlock and edb_unlockall functions, the locked rows are deleted with the edb_delete function, or the cursor's parent command is released with the edb_unprepare function.
Warning If the cursor state, retrievable via the edb_state function, is an insert state (EDB_INSERT_STATE) or update state (EDB_UPDATE_STATE), then this function will cause an automatic call to the edb_post function in order to force the cursor into a browse state (EDB_BROWSE_STATE).

<?php

// The following script connects to an ElevateDB
// Server and database, prepares and executes a
// direct table open, locks the current row in the
// cursor using the edb_lock() function, updates
// the current row, and then unlocks the current row.

$con = edb_connect("type=remote;charset=Ansi;address=127.0.0.1;"+
                   "uid=Administrator;pwd=EDBDefault;database=Test");
if (!$con)
  {
  die("Could not connect: " . edb_errmsg());
  }

$cmd = edb_prepare($con,"customer",EDB_COMMAND_TABLE);
$cursor = edb_execute($cmd);

if (edb_find($cursor,array(1000)))
{
  if (edb_lock($cursor))
    {
    edb_update($cursor);
    edb_setcol($cursor,"Company","My Company 2 - Electric Boogaloo");
    if (!edb_post($cursor))
      {
      $msg = edb_errmsg();
      die("Error updating customer: " . $msg);
      }
    edb_unlock($cursor);
    }
}

edb_disconnect($con);
?>
Image