Advertisement
pcwizz

locking database table example

Feb 20th, 2014
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.19 KB | None | 0 0
  1.                 $i=0;
  2.                 do {
  3.                     $result = $this->mysqli->query("SELECT * FROM `lock` WHERE `table_name`='USER'");
  4.                     $numRows = $result->num_rows;
  5.                     if ($numRows > 0) {
  6.                         echo "Waiting for table (USER) count: " . $i + 1 ;
  7.                         sleep(0.05);
  8.                         $i++;
  9.                     }
  10.                 } while ($numRows > 0 && $i < 9);
  11.                 if ($i == 9) {
  12.                     echo "Previous lock (USER) timeout";
  13.                     $this->mysqli->query("DELETE `lock` WHERE `table_name`='USER' ");
  14.                     echo "Previous lock destroyed (USER)";
  15.                 }
  16.                 $this->mysqli->query("INSERT INTO `lock`(`table_name`) VALUES ('USER')");
  17.                 echo "Lock taken (USER)";
  18.                 $stmt_user->bind_param("ssssss", $this->name, $this->contactNumber, $this->email, $this->password, $this->salt, $this->gender) or trigger_error(mysql_error());
  19.                 $stmt_get_user_id->bind_result($USER_id) or trigger_error(mysql_error());
  20.                 $stmt_user->execute() or trigger_error(mysql_error());
  21.                 $stmt_get_user_id->execute() or trigger_error(mysql_error());
  22.                 $stmt_get_user_id->store_result() or trigger_error(mysql_error());
  23.                 $stmt_get_user_id->fetch() or trigger_error(mysql_error());
  24.                 $this->mysqli->query("DELETE `lock` WHERE `table_name`='USER' ");
  25.                 echo "Lock given up (USER)";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement