Måske sådan noget. (utestet)
$TempSQL = "SELECT field1, field2, field3 FROM table WHERE ";
$args=array();
if ($numberParams == 1) {
$TempSQL = $TempSQL . " field1 = :val1"
$args[':val1']=$val1;
} else {
$TempSQL = $TempSQL . " field2 = :val2 and field3 = :val3";
$args[':val2']=$val2;
$args[':val3']=$val3;
}
$stmt=$db->prepare($TempSQL);
$stmt->execute($args);