Bonjour,

j'ai une classe qui créé une instance PDO en singleton pour mes requêtes SQL :

Code : 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
 
class SPDO
{
  /**
   * Instance de la classe PDO
   *
   * @var PDO
   * @access private
   */ 
  private $PDOInstance = null;
 
   /**
   * Instance de la classe SPDO
   *
   * @var SPDO
   * @access private
   * @static
   */ 
  private static $instance = null;
 
  /**
   * Constante: nom d'utilisateur de la bdd
   *
   * @var string
   */
  const DEFAULT_SQL_USER = 'root';
 
  /**
   * Constante: hôte de la bdd
   *
   * @var string
   */
  const DEFAULT_SQL_HOST = 'localhost';
 
  /**
   * Constante: hôte de la bdd
   *
   * @var string
   */
  const DEFAULT_SQL_PASS = 'monpass';
 
  /**
   * Constante: nom de la bdd
   *
   * @var string
   */
  const DEFAULT_SQL_DTB = 'dispocol';
 
  /**
   * Constructeur
   *
   * @param void
   * @return void
   * @see PDO::__construct()
   * @access private
   */
  private function __construct()
  {
    $this->PDOInstance = new PDO('mysql:dbname='.self::DEFAULT_SQL_DTB.';host='.self::DEFAULT_SQL_HOST,self::DEFAULT_SQL_USER ,self::DEFAULT_SQL_PASS);    
  }
 
   /**
    * Crée et retourne l'objet SPDO
    *
    * @access public
    * @static
    * @param void
    * @return SPDO $instance
    */
  public static function getInstance()
  {  
    if(is_null(self::$instance))
    {
      self::$instance = new SPDO();
    }
    return self::$instance;
  }
 
  /**
   * Exécute une requête SQL avec PDO
   *
   * @param string $query La requête SQL
   * @return PDOStatement Retourne l'objet PDOStatement
   */
  public function query($query)
  {
    return $this->PDOInstance->query($query);
  }
}
et le code php de ma page de réservation de chambre d'hôtel :

Code : 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<!DOCTYPE html>
<html lang=fr>
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<link rel="stylesheet" media="screen" type="text/css" href="css/styles.css"/>
	</head>
 
	<body>
		<?php
		$year0 = date('Y',strtotime('now - 1 year'));					/* définit year n-1 */
		$year1 = date('Y',strtotime('now'));							/* définit year */
		$year2 = date('Y',strtotime('now + 1 year'));					/* définit year n+1 */
		$month1 = date('m',strtotime('now'));							/* définit month */
		$year = !empty($_POST['year']) ? $_POST['year'] : $year1;		/* vérifie si $year est posté */
		$month = !empty($_POST['month']) ? $_POST['month'] : $month1;	/* vérifie si $month est posté */
		require_once("class/class.php");
		?>
		<!-- Début du formulaire général -->
		<form method="post" action="index.php" id="hoteldisp">
			<!-- Menu année / semaine -->
			<ul id="menu">
				<li><a href="#" style="color:yellow">Année <?php echo $year; ?></a>
					<!-- sous-menu annee n-1, n, n+1 -->
					<ul>
					<li><a href="#" onclick="document.getElementById('year').value='<?php echo $year0; ?>';hoteldisp.submit();"><?php echo $year0; ?></a></li>
					<li><a href="#" onclick="document.getElementById('year').value='<?php echo $year1; ?>';hoteldisp.submit();"><?php echo $year1; ?></a></li>
					<li><a href="#" onclick="document.getElementById('year').value='<?php echo $year2; ?>';hoteldisp.submit();"><?php echo $year2; ?></a></li>
					<input type="hidden" name="year" id="year" value="<?php echo $year; ?>">
					</ul>
				</li>
				<!-- Menu semaine -->
				<?php
				$month_tab=array("JANVIER"=>"01","FÉVRIER"=>"02","MARS"=>"03","AVRIL"=>"04","MAI"=>"05","JUIN"=>"06","JUILLET"=>"07","AÔUT"=>"08","SEPTEMBRE"=>"09","OCTOBRE"=>"10","NOVEMBRE"=>"11","DÉCEMBRE"=>"12");
				foreach($month_tab as $month_name => $month_num) {
				?>
					<li><a href="#" onclick="document.getElementById('month').value='<?php echo $month_num;?>';hoteldisp.submit();" style="<?php if ($month_num==$month) {echo 'color:#00d0ff';}?>"><?php echo $month_name; ?></a></li>
				<?php
				}
				?>
				<input type="hidden" name="month" id="month" value="<?php echo $month; ?>">
			</ul>
			<table border="1" width="100%">
				<tr style="text-align:center">
					<td>&nbsp;</td>
					<?php
					for ($num_chb=1;$num_chb<=7;$num_chb++) { /* boucle des 7 chambres */ 
						echo "<td>Chambre $num_chb</td>";
					}
					?>
				</tr>
				<?php
				setlocale(LC_TIME, 'fr', 'fr_FR', 'fr_FR.ISO8859-1'); /* définition des jours en fr */
				for ($i = 1; $i <= cal_days_in_month(CAL_GREGORIAN,$month,$year) ; $i++) /* boucle de tous les jours du mois */
				{
					$date="$year-$month-$i";
					echo "<tr id='calrow'><td>".ucfirst(strftime("%A ", strtotime($date))).$i."</td>";
					for ($num_chb=1;$num_chb<=7;$num_chb++) {
						echo "<td>";
						$req = "SELECT * FROM resa WHERE chambre=$num_chb AND date_1=$date";
						foreach (SPDO::getInstance()->query($req) as $membre)
						{
						echo $membre['nom'];
						}
						echo "</td>";
					}
					echo "</tr>";
				}
				?>
			</table>
		</form>
	</body>
</html>]
mon problème est que ma requête sql
Code : Sélectionner tout - Visualiser dans une fenêtre à part
$req = "SELECT * FROM resa WHERE chambre=$num_chb AND date_1=$date";
ne fonctionne pas, pourtant j'ai bien une date_1=2017-02-15.
Si je retire la condition de la date j'ai bien ma variable $membre['nom'] qui s'affiche pour ma chambre 1.
Je ne vois pas mon erreur ...