I'm making a simple php page that is going to display information from a database, filtered by certain criteria. I would like to know if it's possible to have a PDO SQL query with a variable number of SQL 'where's.
If I was using mysql I would just do something like:
$condition1 = "WHERE male = 1 ";
$condition2 = "AND ethnicity = 1 ";
$condition3 = "";
$queryParam = $condition1 . $condition2 . $condition3;
$sql = "SELECT COUNT(*) from users '$queryParam'
Adding a new line for each condition
The query code doesn't need to be input from the code, I'm just trying to make the code easier to port for different projects.