title: Pass array keys and values to Mysql Query String
body: <p>I have an array represents WHERE clause of my SQL query.</p>
  
  <pre><code>$qWhere= array("cName" =&gt; "Turgay Metal", "cTelephone" =&gt; "5556162"); 
  </code></pre>
  
  <p>my function is: (simplified)</p>
  
  <pre><code>&lt;?php
  function getAll($tableName,$qWhere="") {
  $qWhere = $qWhere == "" ? $qWhere : (" WHERE " . $qWhere);  
  $sql = "SELECT * FROM $tableName $qWhere";}
  </code></pre>
  
  <p>So i need to write another function to kinda serialize array with <code>foreach</code> as <code>$k = '$v'</code>  and then join " AND " then return the string. Finally supply the string into main function:</p>
  
  <pre><code>function arr2sql($qWhere) {
      foreach ($qWhere as $key=&gt;$value) { $fields[] = sprintf("%s = '%s'", $key, secure($value));} 
      $field_list = join(' AND ', $fields); unset($qWhere);
      return $field_list;
  }
  </code></pre>
  
  <p>Is this the correct way or may it be achieved more clean and profesionally?</p>
  
  <p>Thanks for help.</p>