Advertisement
Guest User

lol

a guest
Aug 15th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. <?php
  2.  
  3. // Turn off error reporting
  4. error_reporting(1);
  5.  
  6. class DB {
  7.  
  8. private $host = "127.0.0.1";
  9. private $user = "root";
  10. private $pass = "";
  11. private $db = "ums2";
  12. public $conn;
  13.  
  14. public function __construct() {
  15.  
  16. $this->conn = new mysqli($this->host,$this->user,$this->pass,$this->db);
  17. }
  18.  
  19. public function insert($table,$data = null) {
  20.  
  21. $sql = "INSERT INTO $table";
  22. $row = null;
  23. $value = null;
  24. foreach($data as $key => $val) {
  25. $row .= ",".$key;
  26. $value .= ",'".$val."'";
  27. }
  28. $sql .="(".substr($row,1).")";
  29. $sql .="VALUES(".substr($value,1).")";
  30.  
  31. $query = $this->conn->prepare($sql); //or die($this->conn->error);
  32. $result = $query->execute();
  33. return $result;
  34. }
  35.  
  36. public function get($table, $where = null) {
  37. $sql = "SELECT * FROM $table";
  38. if($where != null) {
  39. $sql .= " WHERE $where";
  40. }
  41.  
  42. $query = $this->conn->query($sql); //or die($this->conn->error);
  43. return $query->fetch_all(MYSQLI_BOTH);
  44.  
  45. }
  46.  
  47. public function filter($data) {
  48.  
  49. $data = strtolower(htmlentities(strip_tags(trim($data))));
  50. return filter_var($data,FILTER_SANITIZE_STRING);
  51. }
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement