Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // CRUD de la table SQL personnes
- class Annonce {
- public $id, $ville, $categorie, $titre, $contenu;
- //attributs de classe qui correspondent aux champs de la table
- private $host,$dbname,$user,$password, $cnx;//paramètres de connexion
- public function __construct($serveur="localhost",$bdd="monsite",$identifiant="root",$mdp=""){
- $this->host =$serveur;
- $this->dbname =$bdd;
- $this->user =$identifiant;
- $this->password =$mdp;
- try
- {
- $this->cnx =new PDO("mysql:host=$this->host;dbname=$this->dbname",$this->user,$this->password);
- }
- catch (Exception $e){
- echo 'Code de l\'Erreur : '.$e->getCode();
- echo 'Message d\'Erreur : '.$e->getMessage();
- }
- }
- public function saveAnnonce(){ //add
- $sql="INSERT INTO annonces(id, ville, categorie, titre, contenu)
- values('','$this->ville','$this->categorie','$this->titre','$this->contenu')";
- $res=$this->cnx->exec($sql);
- if($res) return true;
- else return false;
- }
- public function getAnnonce(){ //affiche
- $sql="Select * from annonces";
- $res=$this->cnx->query($sql);//INEXPLOITABLE
- $data=$res->fetchAll(PDO::FETCH_ASSOC);
- return $data;
- }
- public function searchAnnonce(){ //cherche
- $sql="Select * from annonces WHERE (ville='$this->ville')&&(categorie='$this->categorie')";
- $res=$this->cnx->query($sql);//INEXPLOITABLE
- $data=$res->fetchAll(PDO::FETCH_ASSOC);
- return $data;
- }
- public function deleteAnnonce(){
- $sql="Delete from annonces WHERE categorie='$this->categorie'";
- print $sql;
- $resultat=$this->cnx->exec($sql);//$resultat contient le nombre des lignes affectées
- if($resultat) return true;
- else return false;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement