Advertisement
Guest User

Untitled

a guest
Sep 24th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. <?php
  2. class Connect{
  3. private $host = "localhost";
  4. private $db = "matematyka";
  5. private $user = "root";
  6. private $password = "";
  7.  
  8. public function setConnect($host, $db, $user, $password){
  9. $this->host = $host;
  10. $this->db = $db;
  11. $this->user = $user;
  12. $this->password = $password;
  13. }
  14.  
  15. public function getConnect(){
  16. return $conn = new PDO('mysql:host='.$this->host.';dbname='.$this->db.'',$this->user,$this->password);
  17. }
  18.  
  19. }
  20.  
  21. class QueryDB extends Connect{
  22. private $result;
  23. private $obj;
  24.  
  25. public function setQueryDB($result,$obj){
  26. $this->result = $result;
  27. $this->obj = $obj;
  28. }
  29.  
  30. public function getQueryDB(){
  31. $this->result = $this->getConnect()->query("SELECT * FROM liczby");
  32. $this->obj = $this->result -> fetch(PDO::FETCH_OBJ);
  33. return $this->obj;
  34. }
  35. }
  36.  
  37. $test = new QueryDB;
  38. $test->getQueryDB();
  39.  
  40.  
  41. /*
  42.  
  43. $conn = new PDO(
  44. 'mysql:host=localhost;dbname=matematyka','root',''
  45. );
  46. $result = $conn -> query("SELECT * FROM liczby");
  47. $obj = $result -> fetch(PDO::FETCH_OBJ);
  48.  
  49. function addition($number1,$number2){
  50. return $number1 + $number2;
  51. }
  52. */
  53. ?>
  54.  
  55. <!doctype html>
  56. <html>
  57. <head>
  58. <meta charset="utf-8" />
  59. </head>
  60. <body>
  61. Dodawanie liczb:<br />
  62. <?php ?>
  63. </body>
  64. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement