Advertisement
Guest User

Untitled

a guest
Apr 27th, 2016
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. TWO CLASSES
  2. class USER
  3. {
  4. private $db;
  5.  
  6. function __construct($DB_con)
  7. {
  8. $this->db = $DB_con;
  9. }
  10.  
  11. class FORUM {
  12.  
  13. function __construct($DB_con)
  14. {
  15. $this->db = $DB_con;
  16. }
  17.  
  18. public function getSubject() {
  19. $table = "";
  20. try {
  21. $query = $this->db->prepare("DESCRIBE posts");
  22. $query->execute();
  23. $forumrow = $query->fetchall(PDO::FETCH_COLUMN);
  24. print_r($forumrow);
  25. } catch(PDOException $e) {
  26. echo $e->getMessage();
  27. }
  28. }
  29. }
  30.  
  31. $forum = new FORUM($DB_con);
  32. $forum->getSubject();
  33.  
  34. I have a database conntection too.
  35.  
  36. session_start();
  37.  
  38. $DB_host = "localhost";
  39. $DB_user = "root";
  40. $DB_pass = "";
  41. $DB_name = "dblogin";
  42.  
  43. try
  44. {
  45. $DB_con = new PDO("mysql:host={$DB_host};dbname={$DB_name}",$DB_user,$DB_pass);
  46. $DB_con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  47. }
  48. catch(PDOException $e)
  49. {
  50. echo $e->getMessage();
  51. }
  52.  
  53.  
  54. include_once 'users.php';
  55. $user = new USER($DB_con);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement