Advertisement
Guest User

Untitled

a guest
Aug 11th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. <?php
  2. ini_set("display_errors", 1);
  3. class dbConnect {
  4.  
  5. private $host = "localhost";
  6. private $db = "mybd";
  7. private $user = "root";
  8. public $pdo;
  9. private $pass = "root";
  10. private $charset = "utf8";
  11. public $tableName;
  12. private $opt = [
  13. PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
  14. PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
  15. ];
  16.  
  17. protected function __construct() {
  18. $dsn = "mysql:host=$this->host;dbname=$this->db;charset=$this->charset";
  19. $this->pdo = new PDO($dsn, $this->user, $this->pass, $this->opt);
  20. }
  21.  
  22. public function getAll() {
  23. $stmt = $this->pdo->prepare("SELECT * FROM $this->tableName");
  24. $stmt->execute()->fetchAll();
  25. return $data;
  26. }
  27.  
  28. public function getRow() {
  29. $$stmt = $this->pdo->prepare("SELECT * FROM $this->tableName WHERE id = ?")
  30. $oneRow = $stmt->execute([$id])->fetchAll();
  31. return $oneRow;
  32. }
  33. }
  34. }
  35.  
  36.  
  37.  
  38. class Users extends dbConnect {
  39.  
  40. public $id;
  41.  
  42.  
  43. public function __construct() {
  44. $this->tableName = "users";
  45. parent::__construct();
  46. }
  47. }
  48.  
  49. function dump($variable) {
  50. echo '<pre>';
  51. var_dump($variable);
  52. echo '</pre>';
  53. }
  54.  
  55. $user1 = new Users();
  56. $user1->getAll();
  57.  
  58.  
  59. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement