title: Constructing UPDATE statements using associative arrays in PHP
body: <p>What is the best way to construct an UPDATE statement using associative arrays in PHP?</p>
  
  <p>For example, say I have a function like so:</p>
  
  <pre><code>/**
   * For update queries
   * 
   * @param string $tableName Name of the table we're wanting to update.
   * @param array $values Associative array of columns / values to update. e.g. array('name' =&gt; 'John', 'age' =&gt; 29)
   * @param array $conditions Associative array of conditions. e.g. array('user_id' =&gt; 1) equates to "WHERE user_id = 1"
   */
   public function update($tableName, $values, $conditions = array()){
        //Construct SQL
   }
  </code></pre>
  
  <p>So far, I've been able to construct simple UPDATE statements such as:</p>
  
  <pre><code>UPDATE `myTableName` SET `name` = :name, `age` = :age WHERE `user_id` = :user_id
  </code></pre>
  
  <p>Now I'm left wondering: What is the best way to approach constructing the WHERE clause? Are there similar implementations in other libraries and code bases that I can look into? For example: How do I approach the construction of WHERE clauses that have OR and AND and IN() etc? </p>
  
  <pre><code>UPDATE example SET col = :val WHERE user_id = :user_id AND (age = :age OR name = :name)
  </code></pre>