<?php
class Store{
    // database connection and table name
    private $conn;
    private $table_name = "store";
 
    // object properties
	public $id;
	public $store;
 
    public function __construct($db){
        $this->conn = $db;
    }
	
	function getAllRows(){
		$query = "SELECT id, store FROM " . $this->table_name . "  ORDER BY id";
		$stmt = $this->conn->prepare($query);
		$stmt->execute();
		return $stmt;
	}
	
	function delete(){
		$query = "DELETE FROM " . $this->table_name . " WHERE id = ?";
		$stmt = $this->conn->prepare($query);
		$this->id = htmlspecialchars(strip_tags($this->id));
		$stmt->bindParam(1, $this->id);
		if($stmt->execute()){
			return true;
		}
		return false;
	}
	
	function create(){
		$query = "INSERT INTO " . $this->table_name . " SET store=:store";
		$stmt = $this->conn->prepare($query);
	 
		$this->store=htmlspecialchars(strip_tags($this->store));
	 
		$stmt->bindParam(":store", $this->store);
	 
		if($stmt->execute()){
			return true;
		}	 
		return false;
	}
	
	function exist(){
		$query = "SELECT id FROM " . $this->table_name . " WHERE store = ? LIMIT 0,1";
		$stmt = $this->conn->prepare( $query );
		$this->store=htmlspecialchars(strip_tags($this->store));
	 
		$stmt->bindParam(1, $this->store);
		
		$stmt->execute();
		if($stmt->rowCount()>0){
			return true;
		}
		return false;
	}
}
?>