Advertisement
Guest User

Untitled

a guest
Mar 6th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. <?php
  2. class Database {
  3. protected $host = 'localhost';
  4. protected $user = 'root';
  5. protected $pass = '';
  6. protected $dbname = 'family';
  7. protected $db;
  8. protected $sql_query;
  9. protected $result;
  10. public function __construct() {
  11. $this->db = new PDO("mysql:host=".$this->host.";dbname=".$this->dbname, $this->user, $this->pass);
  12. $this->db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
  13. }
  14. public function query($query = null) {
  15. //$this->sql_query = $query;
  16. $sql = ($query != null) ? $query : $this->sql_query;
  17. try {
  18. //$query
  19. $q = $this->prepare($sql);
  20. $result = $q->execute();
  21. $thi->result = $result;
  22. } catch(PDOException $e) {
  23. die("ERROR: " . $e->getMesage());
  24. }
  25. }
  26. public function select($items) {
  27. $this->sql_query .= "SELECT $items";
  28. }
  29. public function from($table) {
  30. $this->sql_query .= " FROM $table";
  31. }
  32. public function where($fields, $value) {
  33. $this->sql_query .= " WHERE $fields = $value";
  34. }
  35. public function get_data() {
  36. return $this->result;
  37. }
  38. }
  39. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement