<?

class DB {

	private $conn = null;

	function __construct($database="bl"){
		$host="192.168.1.14";
		$user="gogs";
		$password="A1s2d3f4g5";
		// $database="bl";
		$database= $database;

		$this->conn = new mysqli($host, $user, $password, $database);
	}

	function arrayToInsertSql($table, $arr){
		$sql = "insert into ".$table." ";

		$sql .= "(";
		$i = 0;
		foreach($arr as $title => $value){
			if($i > 0) $sql .= ",";
			$sql .= "`";
			$sql .= $title;
			$sql .= "`";
			$i++;
		}
		$sql .= ") ";


		$sql .= "select ";
		$i = 0;
		foreach($arr as $title => $value){
			if($i > 0) $sql .= ",";
			$sql .= "'";
			// $sql .= htmlspecialchars($value);
			$sql .= addslashes($value);
			$sql .= "'";
			$i++;

		}
		return $sql;
	}

	function runSql($sql){
		$result = $this->conn->query($sql);
		return $result->fetch_all(MYSQLI_ASSOC);
	}

	function execSql($sql){
		$result = $this->conn->query($sql);
		// return $result;
	}

	function insert_id(){
		return $this->conn->insert_id;
	}


}




?>