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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
<?php
class PdoCombattant extends PdoConnect {
public function create(combattant $combattant) {
try {
$this->open();
$sql = "INSERT INTO `combattant`(NOMCOMBATTANT, PRENOMCOMBATTANT, SURNOMCOMBATTANT,ALLONGECOMBATTANT,TAILLECOMBATTANT,POIDSCOMBATTANT,PHOTOCOMBATTANT, IDPAYS) VALUES(?, ?, ?, ?, ?, ?, ?, ?) ";
$prep = $this->pdo->prepare($sql);
$prep->bindValue(1, $combattant->getNomCombattant(), PDO:: PARAM_STR);
$prep->bindValue(2, $combattant->getPrenomCombattant(), PDO:: PARAM_STR);
$prep->bindValue(3, $combattant->getSurnomCombattant(), PDO:: PARAM_STR);
$prep->bindValue(4, $combattant->getAllongeCombattant(), PDO:: PARAM_INT);
$prep->bindValue(5, $combattant->getTailleCombattant(), PDO:: PARAM_INT);
$prep->bindValue(6, $combattant->getPoidsCombattant(), PDO:: PARAM_INT);
$prep->bindValue(7, $combattant->getPhotoCombattant(), PDO:: PARAM_STR);
$prep->bindValue(8, $combattant->getIdPays(), PDO:: PARAM_INT);
$prep->execute();
} catch (PDOException $e) {
$msg = 'ERREUR PDO dans ' . $e->getFile() . ' L.' . $e->getLine() . ' : ' . $e->getMessage();
die($msg);
}
}
public function readAll() {
try {
$this->open();
$sql = "SELECT * From `combattant`";
$prep = $this->pdo->prepare($sql);
$prep->execute();
$prep->setFetchMode(PDO::FETCH_ASSOC);
return $prep;
} catch (PDOException $e) {
$msg = 'ERREUR PDO dans ' . $e->getFile() . ' L.' . $e->getLine() . ' : ' . $e->getMessage();
die($msg);
}
}
public function readOne($IdCombattant) {
try {
$this->open();
$sql = "SELECT * From `combattant` Where IdCombattant=$IdCombattant";
$prep = $this->pdo->prepare($sql);
$prep->execute();
$combattant = new Combattant();
$ligne = $prep->fetch(PDO::FETCH_OBJ);
$combattant->setIdCombattant($ligne->IDCOMBATTANT);
$combattant->setNomCombattant($ligne->NOMCOMBATTANT);
$combattant->setPrenomCombattant($ligne->PRENOMCOMBATTANT);
$combattant->setSurnomCombattant($ligne->SURNOMCOMBATTANT);
$combattant->setTailleCombattant($ligne->TAILLECOMBATTANT);
$combattant->setPoidsCombattant($ligne->POIDSCOMBATTANT);
$combattant->setPhotoCombattant($ligne->PHOTOCOMBATTANT);
$combattant->setAllongeCombattant($ligne->ALLONGECOMBATTANT);
$combattant->setIdPays($ligne->IDPAYS);
return $combattant;
} catch (PDOException $e) {
$msg = 'ERREUR PDO dans ' . $e->getFile() . ' L.' . $e->getLine() . ' : ' . $e->getMessage();
die($msg);
}
}
public function delete(combattant $combattant) {
try {
$this->open();
$sql = "DELETE FROM combattant WHERE IDCOMBATTANT=?";
$prep = $this->pdo->prepare($sql);
$prep->bindValue(1, $combattant->getIdCombattant(), PDO::PARAM_INT);
$prep->execute();
} catch (PDOException $e) {
$msg = 'ERREUR PDO dans ' . $e->getFile() . ' L.' . $e->getLine() . ' : ' . $e->getMessage();
die($msg);
}
}
public function update(combattant $combattant) {
$this->open();
$sql = "UPDATE combattant SET NOMCOMBATTANT = ?, PRENOMCOMBATTANT= ?, SURNOMCOMBATTANT = ?, ALLONGECOMBATTANT = ?, TAILLECOMBATTANT = ?, POIDSCOMBATTANT = ?, PHOTOCOMBATTANT = ?, IDPAYS = ? WHERE IDCOMBATTANT= ?";
$prep = $this->pdo->prepare($sql);
$prep->bindValue(1, $combattant->getNomCombattant(), PDO:: PARAM_STR);
$prep->bindValue(2, $combattant->getPrenomCombattant(), PDO:: PARAM_STR);
$prep->bindValue(3, $combattant->getSurnomCombattant(), PDO:: PARAM_STR);
$prep->bindValue(4, $combattant->getAllongeCombattant(), PDO:: PARAM_INT);
$prep->bindValue(5, $combattant->getTailleCombattant(), PDO:: PARAM_INT);
$prep->bindValue(6, $combattant->getPoidsCombattant(), PDO:: PARAM_INT);
$prep->bindValue(7, $combattant->getPhotoCombattant(), PDO:: PARAM_STR);
$prep->bindValue(8, $combattant->getIdCombattants(), PDO:: PARAM_INT);
$prep->bindValue(9, $combattant->getIdPays(), PDO:: PARAM_INT);
$prep->execute();
}
public function exist($surnom) {
$this->open();
$query = "SELECT * FROM combattant WHERE SURNOMCOMBATTANT='$surnom';";
$statement = $this->pdo->query($query);
return $statement->rowCount();
}
} |
Partager