title: PDO : creating a reusable code
body: <p>I'm trying to create a reusable code in PDO.</p>
  
  <p>here's my code.</p>
  
  <pre><code>$myClass = new main_c();
  $condition = "email_address = :email_address AND password = :password";
  $array = array('email_address' =&gt; 'yiihii@yahoo.com', 'password' =&gt; '98467a817e2ff8c8377c1bf085da7138');
  $row = $myClass-&gt;get('user', $condition, $array, $db);
  print_r($row);
  </code></pre>
  
  <p>Here's my function.</p>
  
  <pre><code>      public function get($tablename, $condition, $array, $db){
  
          $stmt = $db-&gt;prepare("SELECT * FROM $tablename WHERE $condition");
          foreach($array as $k=&gt;$v){
  
              $stmt-&gt;bindParam(":$k", $v);
          }
  
          try{
              $stmt-&gt;execute();
          }catch(PDOException $e){
              $error = new main_c();
              echo $error-&gt;error_handling($e);
          }
  
          return $row=$stmt-&gt;fetch(PDO::FETCH_ASSOC);
          }
  </code></pre>
  
  <p>I've tried omitting the <code>AND</code> in the condition and just put a single where clause and it worked. I think there's a problem in the foreach. i'm not sure though.</p>