title: PDO PHP bindParam() repeated use of same parameters
body: <p>Yesterday i decided to learn PDO and rewrite our server php to PDO.</p>
  
  <p>The thing that jumped to my mind while rewriting the code is the need of repeated use of bindParam for the same parameters i already used.</p>
  
  <p>Here is an example:</p>
  
  <pre><code>$dbh-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  
      $dbh-&gt;beginTransaction();
      $stmt = $dbh-&gt;prepare("INSERT INTO Products(productID,numOfLikes) VALUES (:productID,0) ON DUPLICATE KEY UPDATE productID = productID;");
      $stmt-&gt;bindParam(":productID",$productID);
      $stmt-&gt;execute();
  
      if($customerID !== 0){  
          //*****Check, if customerID is in the Database, else add the customerID to the Database.
          $stmt = $dbh-&gt;prepare("INSERT INTO Customers(customerID) VALUES (:customerID) ON DUPLICATE KEY UPDATE customerID = customerID;");
          $stmt-&gt;bindParam(":customerID",$customerID);
          $stmt-&gt;execute();
  
          //*****if customerID and productID are NOT registered together ,then register and add +1 to productID numOfLikes
          $stmt = $dbh-&gt;prepare("SELECT customerID, productID FROM CustomerProducts WHERE productID = :productID AND customerID = :customerID");          
          $stmt-&gt;bindParam(":productID",$productID);
          $stmt-&gt;bindParam(":customerID",$customerID);
          $stmt-&gt;execute();
  
          if ($stmt-&gt;rowCount() == 0) {
              //echo "added";
              $stmt = $dbh-&gt;prepare("INSERT INTO CustomerProducts(customerID, productID) Values (:customerID,:productID)");
              $stmt-&gt;bindParam(":customerID",$customerID);
              $stmt-&gt;bindParam(":productID",$productID);
              $stmt-&gt;execute();
  
              $stmt = $dbh-&gt;prepare("UPDATE Products SET numOfLikes = numOfLikes + 1 WHERE productID = :productID");
              $stmt-&gt;bindParam(":productID",$productID);
              $stmt-&gt;execute();  
          }else {
              //echo "removed";
              $stmt = $dbh-&gt;prepare("DELETE FROM CustomerProducts WHERE productID = ".$productID." AND customerID = ".$customerID);
              $stmt-&gt;bindParam(":customerID",$customerID);
              $stmt-&gt;bindParam(":productID",$productID);
              $stmt-&gt;execute();
  
              $stmt = $dbh-&gt;prepare("UPDATE Products SET numOfLikes = numOfLikes - 1 WHERE productID = ".$productID);
              $stmt-&gt;bindParam(":productID",$productID);
              $stmt-&gt;execute();  
          }
      }
      $dbh-&gt;commit();
  </code></pre>
  
  <p>Is there a way to write it in "prettier way"?
  Can you see any flows in that could. I would appreciate every help.</p>
  
  <p>Note: this code will be for production use in the near future.</p>