Advertisement
Guest User

Untitled

a guest
Aug 1st, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.12 KB | None | 0 0
  1. ##fichier forum.class.php##
  2. <?php
  3. class Forum{
  4.  
  5.     private $db;
  6.     private $results;
  7.    
  8.     function __construct() {
  9.         $db = new DBConnect();
  10.  
  11.     }
  12.  
  13.     function show_topics() {
  14.         $results = $this->results;
  15.         $results = $this->db->query('SELECT * FROM forum_topics');
  16.         $results = $results->fetch();
  17.  
  18.         return $results;
  19.     }
  20.  
  21.     function show_replies($id) {
  22.  
  23.     }
  24.  
  25. }
  26. ?>
  27.  
  28. ##fichier dbconnect.class.php##
  29. <?php
  30.  
  31. class DBconnect extends PDO {
  32.    
  33. private $db_user = 'root';
  34. private $db_pass = '';
  35. private $db_name = 'mysql:host=127.0.0.1;dbname=blog';
  36.  
  37.       function  __construct() {
  38.                
  39.         parent::__construct($this->db_name, $this->db_user, $this->db_pass);
  40.         parent::setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
  41.  
  42.        
  43.        }
  44.  
  45. }
  46. ?>
  47.  
  48. ##fichier index.php##
  49. <?php
  50. require("core.php");
  51. loadclass('dbconnect');
  52. loadclass('forum');
  53.  
  54. $res = new Forum();
  55. $results = $res->show_topics();
  56.  
  57.  
  58. print_r($results);
  59.  
  60. foreach($results as $a => $b) {
  61.     echo "<pre>";
  62.     echo "$a => $b";
  63.     echo "</pre>";
  64. }
  65. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement