I have written this function that surprisingly works. (I didn't really know what I was doing; just a little experiment.) It is supposed to count rows selected by a PDO query.
Is it well written? It works, but I am just asking, as it is my first more-complex function.
function countRows($sql, $parameters){
require("include/db.php");
$result = $db->prepare($sql);
foreach ($parameters as $key => $parameter) {
$result->bindParam($key, $parameter);
}
$result->execute();
$number_of_rows = $result->fetchColumn();
return $number_of_rows;
}