title: dynamic class or function return query result PDO
body: <p>I used to have one function to any select query in my script, but since it's not secure I need to find out how to make a dynamic PDO class in php.</p>
  
  <p>For example, I used to use this code.</p>
  
  <pre><code>function excute_query ($Query)
  {
  
      if($Query_Run = mysql_query($Query))
      {
          while($DATA = mysql_fetch_array($Query_Run, MYSQL_ASSOC))
              {
                  $data_array[] = $DATA;
              }
              return $data_array;
              close();
  
      }
      else{
              die(mysql_error());
          }
  
      mysql_close();
  
  }
  </code></pre>
  
  <p>and I can use it anywhere in my script and it return's an array with the data. in 2 lines.</p>
  
  <pre><code>$sql = 'SELECT * FROM users';
  $users = execute_query($sql);
  </code></pre>
  
  <p>Now I need to use the same function with PDO. I've been trying, but how I can make a class or function to do the same using PDO. </p>
  
  <p>What I'm trying to say. instead of write same 4 lines to make a query, is there any way to make a function or class take a query and return the data ?</p>
  
  <p>Thank you.</p>