1 2 3 4 5 6 7 8 9 10 11
| $issetor = fn (&$value, $column) => isset($value) ? $pdo->quote($value) : $column;
$if = fn ($condition, $if_true, $if_false = '') => $condition ? $if_true : $if_false;
$sql = <<<SQL
SELECT DISTINCT id, name
FROM animals
{$if(isset($_GET['continent']), "INNER JOIN animalContinent ON animals.id = animalContinent.animal_id AND animalContinent.continent_idcontinent = {$pdo->quote($_GET['continent'])}")}
WHERE TRUE
AND species_idspecies = {$issetor($_GET['species'], 'species_idspecies')}
AND diet_iddiet = {$issetor($_GET['diet'], 'diet_iddiet')}
SQL; |
Partager