function getDBResults($sql, $params=array()) {
global $pdo; // you should NEVER connect in a function! But use already opened.
$stmt = $pdo->prepare($sql);
$stmt->execute($params);
return $stmt->fetchAll();
}
see - three simple lines.
here is all the info you need. Just remember you have to connect only once per application and use this connection all the way.