Bonjour,

J'ai la fonction suivante qui fonctionne avec des variables PHP dans la requête mais que je n'arrive pas à paramétrer. J'obtiens une erreur parameter number.
Dans le code ci-dessous, la première variante fonctionne bien mais pas les deux autres.
Pour éviter une question qui m'a déjà été posée, je précise que j'ai déjà couramment réalisé des requêtes en utilisant plusieurs fois un même paramètre et que cela fonctionne très bien.
Code php : Sélectionner tout - Visualiser dans une fenêtre à part
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
49
50
51
52
53
54
55
function getSpouses($gender, $selection=null, $minGap=null, $maxGap=null, $spouse1=null)
{
	global $db;
 
	$dateFormat = LOCAL_DATE_FORMAT;
	$where = "id_abo=:id_abo AND gender=:gender";
	if (!$selection and isset($minGap, $maxGap, $spouse1))
	{
		$where .= "
			AND (
				(birth_date BETWEEN('$spouse1->birth_date' - INTERVAL $maxGap YEAR) AND ('$spouse1->birth_date' - INTERVAL $minGap YEAR))
			OR
				(birth_date BETWEEN('$spouse1->birth_date' + INTERVAL $minGap YEAR) AND ('$spouse1->birth_date' + INTERVAL $maxGap YEAR))
				)
		";
		/*
		$where .= "
			AND (
				(birth_date BETWEEN(:refBirthdate - INTERVAL $maxGap YEAR) AND (:refBirthdate - INTERVAL $minGap YEAR))
			OR
				(birth_date BETWEEN(:refBirthdate + INTERVAL $minGap YEAR) AND (:refBirthdate + INTERVAL $maxGap YEAR))
				)
		";
		*/
		/*
		$where .= "
			AND (
				(birth_date BETWEEN('$spouse1->birth_date' - INTERVAL :maxGap YEAR) AND ('$spouse1->birth_date' - INTERVAL :minGap YEAR))
			OR
				(birth_date BETWEEN('$spouse1->birth_date' + INTERVAL :minGap YEAR) AND ('$spouse1->birth_date' + INTERVAL :maxGap YEAR))
				)
		";
		*/
	}
	if (empty($selection) and empty($minGap) and empty($maxGap))
	{
		$where.= " AND birth_date IS NULL";
	}
	$query = "
		SELECT
			id, last_name, first_name, middle_name, CONCAT(COALESCE(last_name, ''), ' ', COALESCE(first_name, ''), ', ', COALESCE(middle_name, '')) AS full_name,
			DATE_FORMAT(birth_date, '$dateFormat') AS birth_date, ' - ',
			DATE_FORMAT(death_date, '$dateFormat') AS death_date
		FROM dat_persons
		WHERE $where
	;";
	$result = $db->prepare($query);
	$result->bindParam('id_abo', $_SESSION['user']['id_abo']);
	$result->bindParam('gender', $gender);
	//$result->bindParam('refBirthdate', $spouse1->birth_date);
	//$result->bindParam('minGap', $minGap);
	//$result->bindParam('maxGap', $maxGap);
	$result->execute();
	return $result->fetchAll();
}