Advertisement
Guest User

Untitled

a guest
Jul 31st, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. class User extends Database
  2. {
  3.  
  4. public function data($userid)
  5. {
  6. $getRow = $this->getConnect()->getRow("SELECT * FROM users WHERE userid = ?", [$userid]);
  7.  
  8. return $getRow;
  9. }
  10.  
  11. }
  12.  
  13. class Database
  14. {
  15.  
  16. private $dbh = NULL;
  17. private $instance = NULL;
  18.  
  19. public function __construct($username = 'root', $password = '', $host = '127.0.0.1', $dbname = 'testdb', $options = [])
  20. {
  21. try {
  22. $this->dbh = new PDO("mysql:dbname={$dbname};host={$host};charset=utf8", $username, $password);
  23. $this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  24. $this->dbh->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
  25. } catch (PDOException $ex) {
  26. throw new Exception($ex->getMessage());
  27. }
  28.  
  29. }
  30.  
  31. public function getConnect()
  32. {
  33. if($this->instance == NULL)
  34. {
  35. $this->instance = new self();
  36. }
  37. return $this->instance;
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement