Guest User

Untitled

a guest
Mar 6th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. <?php
  2. class Database{
  3. public $isConn;
  4. protected $data;
  5.  
  6. public function __construct($username = "root", $password = "", $host = "127.0.0.1", $dbname = "test", $options = []){
  7. $this->isConn = TRUE;
  8. $this->data = new PDO("mysql:host=$host;dbname=$dbname;charset=utf8", $username, $password, $options);
  9. $this->data->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  10. $this->data->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
  11. }
  12.  
  13. public function Disconnect(){
  14. $this->data = NULL;
  15. $this->isConn = FALSE;
  16. }
  17.  
  18. public function getRow($params = []){
  19. $stmt = $this->data->prepare("SELECT * FROM users WHERE id = ?");
  20. $stmt->execute($params);
  21. return $stmt->fetch();
  22. }
  23. }
  24. $user = new Database();
  25. ?>
Add Comment
Please, Sign In to add comment