Advertisement
Guest User

Untitled

a guest
Jan 21st, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. class ArticleManager {
  2. private $_db;
  3.  
  4.  
  5. public function __construct($db){
  6. $this->setDb($db);
  7. }
  8.  
  9. public function setDb(PDO $db){
  10. $this->_db = $db;
  11. }
  12.  
  13. public function addArticle(Article $article){
  14. $req = $this->_db->prepare('INSERT INTO articles(titreArticle, textArticle) VALUES (:titreArticle , :textArticle)');
  15. $req->execute(array(
  16. 'titreArticle' => $article->getTitre(),
  17. 'textArticle' => $article->getText(),
  18. ));
  19. }
  20.  
  21. public function deleteArticle($id){
  22. $this->_db->exec('DELETE FROM articles WHERE id =' .$perso->getId());
  23. }
  24.  
  25. public function getList(){
  26.  
  27. $article = [];
  28.  
  29. $req = $this->_db->query('SELECT titreArticle FROM articles');
  30. while ($donnees = $req->fetch(PDO::FETCH_ASSOC))
  31. {
  32. $article[] = new Article($donnees);
  33. }
  34. return $article;
  35. }
  36.  
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement