Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Turn off error reporting
- error_reporting(1);
- class DB {
- private $host = "127.0.0.1";
- private $user = "root";
- private $pass = "";
- private $db = "ums2";
- public $conn;
- public function __construct() {
- $this->conn = new mysqli($this->host,$this->user,$this->pass,$this->db);
- }
- public function insert($table,$data = null) {
- $sql = "INSERT INTO $table";
- $row = null;
- $value = null;
- foreach($data as $key => $val) {
- $row .= ",".$key;
- $value .= ",'".$val."'";
- }
- $sql .="(".substr($row,1).")";
- $sql .="VALUES(".substr($value,1).")";
- $query = $this->conn->prepare($sql); //or die($this->conn->error);
- $result = $query->execute();
- return $result;
- }
- public function get($table, $where = null) {
- $sql = "SELECT * FROM $table";
- if($where != null) {
- $sql .= " WHERE $where";
- }
- $query = $this->conn->query($sql); //or die($this->conn->error);
- return $query->fetch_all(MYSQLI_BOTH);
- }
- public function filter($data) {
- $data = strtolower(htmlentities(strip_tags(trim($data))));
- return filter_var($data,FILTER_SANITIZE_STRING);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement