Advertisement
Guest User

Untitled

a guest
Aug 11th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. <?php
  2. class Database
  3. {
  4. // CONFIGS DEFAULT
  5. private $host = 'localhost';
  6. private $db = 'test';
  7. private $user = 'root';
  8. private $password = 'root';
  9. private $charset = 'utf8';
  10. private $options = [
  11. PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
  12. PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
  13. ];
  14.  
  15. // CONFIGS OTHER
  16. private $dsn;
  17. public $pdo;
  18. public $tableName;
  19. public $id;
  20.  
  21. // METHODS
  22. public function __construct() {
  23. $this->dsn = "mysql:host=$this->host;dbname=$this->db;charset=$this->charset";
  24. $this->pdo = new PDO($this->dsn, $this->user, $this->password, $this->options);
  25. }
  26.  
  27. public function getDsn() {
  28. return $this->dsn;
  29. }
  30.  
  31. public function getAll() {
  32. $stmt = $this->pdo->query("SELECT * FROM $this->tableName");
  33. return $stmt->fetchAll();
  34. }
  35.  
  36. public function getOne() {
  37. $stmt = $this->pdo->query("SELECT * FROM $this->tableName WHERE id = $this->id");
  38. return $stmt->fetchAll();
  39. }
  40.  
  41. public function deleteAll() {
  42. $this->pdo->query("DELETE FROM $this->tableName");
  43. }
  44.  
  45. public function deleteOne() {
  46. $this->pdo->query("DELETE FROM $this->tableName WHERE id = $this->id");
  47. }
  48.  
  49. public function updateOne($setParams) {
  50. $this->pdo->query("UPDATE $this->tableName SET $setParams WHERE id = $this->id");
  51. }
  52.  
  53. public function insert($setParams) {
  54. $this->pdo->query("INSERT INTO $this->tableName SET $setParams");
  55. }
  56. }
  57. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement