[phplib] Table Locking From: Matt Friedman (matt <email protected>)
Date: 11/10/00

I just copied the code below from the mysql database lib contained within phplib.

There's no mention that I could find of these methods in the docs. I'm just wondering: If I need to lock my tables can I just call these methods directly?

If I had time I'd love to update the docs. They seem to be out of date in places.

Thanks!
Matt.

  /* public: table locking */
  function lock($table, $mode="write") {
    $this->connect();
    
    $query="lock tables ";
    if (is_array($table)) {
      while (list($key,$value)=each($table)) {
        if ($key=="read" && $key!=0) {
          $query.="$value read, ";
        } else {
          $query.="$value $mode, ";
        }
      }
      $query=substr($query,0,-2);
    } else {
      $query.="$table $mode";
    }
    $res =  <email protected>($query, $this->Link_ID);
    if (!$res) {
      $this->halt("lock($table, $mode) failed.");
      return 0;
    }
    return $res;
  }
  
  function unlock() {
    $this->connect();

    $res =  <email protected>("unlock tables");
    if (!$res) {
      $this->halt("unlock() failed.");
      return 0;
    }
    return $res;
  }