1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| function searchParents(int $idAbo, array $clauses=[]): array|false {
$db = dbConnect();
var_dump($clauses);
$where = [];
$where[]= "id_abo=:idAbo";
$params = [':idAbo'=>$idAbo, ];
foreach($clauses as $key=>$clause) {
if( in_array($key, ['gender', 'lastname', 'firstname', ]) ){
$where[] = "{$key}=:{$key}";
$params[":$key"]= "{$key}";
}
}
if( !empty('birthY1') && !empty('birthY2') ){
$where[] = "( birthyear BETWEEN :birthY1 AND :birthY2 ) OR birthyear IS NULL";
$params[":birthY1"] = "birthY1";
$params[":birthY2"] = "birthY2";
}
if( !empty('deathY1') && !empty('deathY2') ){
$where[] = "( deathyear BETWEEN :deathY1 AND :deathY2 ) OR deathyear IS NULL";
$params[":deathY1"] = "deathY1";
$params[":deathY2"] = "deathY2";
}
$where = implode("\nAND ", $where);
var_dump($where);
var_dump($params);
$sql = <<<SQL
SELECT
id, CONCAT( COALESCE(UPPER(lastname), ''), ' ', COALESCE(firstname, ''), ' ', COALESCE(middlename, '') ) AS fullname,
CONCAT( COALESCE(birthday, '--'), '/', COALESCE(birthmonth, '--'), '/', COALESCE(birthyear, '----') ) AS birthdate,
' - ', CONCAT( COALESCE(deathday, '--'), '/', COALESCE(deathmonth, '--'), '/', COALESCE(deathyear, '----') ) AS deathdate
FROM dat_persons
WHERE {$where}
ORDER BY lastname, firstname, birthyear, birthmonth, birthday
SQL;
$stmt = $db->prepare($sql);
$stmt->execute($params);
var_dump($stmt->fetchAll() );
return $stmt->fetchAll();
} |
Partager