<?php
class pratikDb
{
	public $conn;
    public function connect($DBHOST, $DBUSER, $DBPASS, $DBNAME)
    {
		if(!$this->conn)
		{
			$this->conn=mysqli_connect($DBHOST, $DBUSER, $DBPASS, $DBNAME);
			//$this->conn = new mysql($DBHOST, $DBUSER, $DBPASS, $DBNAME);
			if ($this->conn->connect_error)
			{
				die("Connection failed: " . $conn->connect_error);
			}
			$this->conn->set_charset("utf8");
		}
    }
	public function disconnect()
    {
		$this->conn->close();
	}
	function real_escape_string($string) // veritabanında sq çalıştırmak
	{
		  return $this->conn->real_escape_string($string);
		
	}
	function query($sql) // veritabanında sq çalıştırmak
	{
		  return $this->conn->query($sql);
		
	}
	
	function get($table, $key=false, $filter='', $order='') // veritabanından bilgi okumak
	{
		  if($filter!='') $filter = 'WHERE '.$filter;
		  if( $table == '' )
		  {
			  return false;
		  }
		  $sql= "SELECT * FROM ".DBPREFIX. $table." ".$filter.' '.$order.";" ;
		  $query = $this->conn->query($sql);
		  $result = array();
		  if( $query )
		  {
			  if($key)
			  {
				  $row = $query->fetch_assoc();
				  $result = $row[$key];
			  } else {		  
				  while($row = $query->fetch_assoc()) 
				  {
					  $result[] = $row;
				  }
			  }
		  }
		 return $result;
	}
}

?>
