Bonjour,
J'essaye de voir depuis 2 jours comment instantier un client qui se connecte. Pour ça, je dois faire une requête qui me retourne le nom du client (ou rien si le login n'est pas bon).
C'est là que je planche. Impossible de tester si mon résultat est vide. La condition laisse toujours passer.
Je débute tout à fait en PHP, merci d'être compatissant.
Voici mon test
C'est la ligne if ($nombre['Nombre'] == '1') qui me pose le problème.
J'ai fait un select count(*) AS `Nombre`where login = varlogin (dans une procédure stockée.
Donc, si le login existe, il me retourne la valeur 1.
Avant j'avais fait un select col1, col2, etc... et dans la classe client pour ma condition, j'avais fait un if($reponse) puis un if ($response = $listClient->fetch().
Rien ne fonctionne.
Help me please.
Voici ma classe DAO qui accède à la base de données MySQL.
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 <?php class Client { private $idClient; private $nom; private $prenom; private $role; private $login; private $motDePasse; private $compteur; private $dateDeNaissance; private $sexe; public $nombre; function __construct($login, $motDePasse) { $this->login = $login; $this->motDePasse = $motDePasse; $this->authClient(); } function authClient() { $nombreClient = DAO::clientExist($this->login); $nombre = $nombreClient->fetch(); if ($nombre['Nombre'] == '1') { $this->nombre = $nombre['Nombre']; $nombreClient->closecursor(); $listClient = DAO::listClientParLogin($this->login); $reponse = $listClient->fetch(); $this->idClient = $reponse['IdClient']; $this->nom = $reponse['Nom']; $this->prenom = $reponse['Prenom']; $this->role = $reponse['Role']; $this->compteur = $reponse['Compteur']; $this->dateDeNaissance = $reponse['DateDeNaissance']; $this->sexe = $reponse['Sexe']; $listClient->closecursor(); if ($this->compteur >= 3) { return 0; } else { $listClient = DAO::listClientParLoginMotDePasse($this->motDePasse, $this->login); $reponse = $listClient->fetch(); if ($reponse['Nombre'] == 1) { $this->compteur = 0; $listClient->closecursor(); $listClient = DAO::updateClientCompteur($this->compteur, $this->idClient); $listClient->closecursor(); return 1; } else { $this->compteur +=1; $listClient->closecursor(); $listClient = DAO::updateClientCompteur($this->compteur, $this->idClient); $listClient->closecursor(); } return -1; } } else { return -2; } }
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 <?php class DAO { /** * @var Singleton * @access private * @static */ private static $_instance = null; private static $bdd; private static $cle = '************'; /** * Constructeur de la classe * * @param void * @return void */ private function __construct() { } public static function getInstance() { if (is_null(self::$_instance)) { self::$_instance = new DAO(); } return self::$_instance; } public static function listAnnees() { $listAnnees = self::$bdd->query('call listAnnees()'); return $listAnnees; } public static function getConnexion() { try { $pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION; $bdd = new PDO('mysql:host=localhost;dbname=courrier', 'root', '', $pdo_options); } catch (Exception $e) { die('Erreur : ' . $e->getMessage()); } self::$bdd = $bdd; return $bdd; } public static function listClientParLogin($login) { $listClient = self::$bdd->query('call listClientParLogin(\'' . $login . '\',\'' . self::$cle . '\')'); return $listClient; } public static function listClientParLoginMotDePasse($motDePasse, $login) { $listClient = self::$bdd->query('call listClientParLoginMotDePasse(\'' . $motDePasse . '\',\'' . $login . '\',\'' . self::$cle . '\')'); return $listClient; } public static function updateClientCompteur($compteur, $idclient) { $listClient = self::$bdd->query('call updateClientCompteur (' . $compteur . ',' . $idclient . ');'); return $listClient; } public static function clientExist($login) { $nombreClient = self::$bdd->query('call clientExist (\'' . $login . '\',\'' . self::$cle . '\')'); return $nombreClient; } } ?>
Partager