title: Locking tables in mysql using php errors
body: <p>I am trying to implement a table lock on my database for a sample shopping website hosted locally.</p>
  
  <p>The following is a sample of my index.php:</p>
  
  <pre><code>case "add":             
      if(!empty($_POST["quantity"])) {
          if(!isset($timestamp)){
              $timestamp = time();
              $lock = $db_handle-&gt;runQuery("LOCK TABLE orders_f write, prod_f read");
          }
          $productByCode = $db_handle-&gt;runQuery("SELECT * FROM prod_f WHERE code='" . $_GET["code"] . "'");
          $itemArray = array($productByCode[0]["code"]=&gt;array('name'=&gt;$productByCode[0]["name"], 'code'=&gt;$productByCode[0]["code"], 'quantity'=&gt;$_POST["quantity"], 'price'=&gt;$productByCode[0]["price"]));
  
          if(!empty($_SESSION["cart_item"])) {
              if(in_array($productByCode[0]["code"],array_keys($_SESSION["cart_item"]))) {
                  foreach($_SESSION["cart_item"] as $k =&gt; $v) {
                      if($productByCode[0]["code"] == $k) {
                          if(empty($_SESSION["cart_item"][$k]["quantity"])) {
                              $_SESSION["cart_item"][$k]["quantity"] = 0;
                          }
                          $_SESSION["cart_item"][$k]["quantity"] += $_POST["quantity"];
                      }
                  }
              } else {
                  $_SESSION["cart_item"] = array_merge($_SESSION["cart_item"],$itemArray);
              }
          } else {
              $_SESSION["cart_item"] = $itemArray;
          }
  </code></pre>
  
  <p>Where the table lock has been enforced. I get the following error when I try to add in the cart, which is the source of the case statement above:</p>
  
  <blockquote>
    <p>Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given in path\dbcontroller.php on line 24
    Here is a snippet of my dbcontroller.php:</p>
  </blockquote>
  
  <pre><code>function runQuery($query) {
      $result = mysqli_query($this-&gt;conn,$query);
      while($row=mysqli_fetch_assoc($result)) {
          $resultset[] = $row;
      }       
      if(!empty($resultset))
          return $resultset;
      else
          return false;
  }
  </code></pre>
  
  <p>I've been searching all night on Youtube and on Stackoverflow but none of the options seem to be working. It is on an <code>Apache</code> server using Wamp on a <code>64 bit Windows 10</code> machine. Please, any suggestions are welcomed.</p>