<?php

class DB{
	//database configuration
	private $dbHost     = "localhost";
	private $dbUsername = "immob049_nwlgama";
	private $dbPassword = "wW+=!tt^)wy#";
	private $dbName     = "immob049_nwlgama";
	private $imgTbl     = 'tour';
	 
	function __construct(){
		if(!isset($this->db)){
            // Connect to the database
            $conn = new mysqli($this->dbHost, $this->dbUsername, $this->dbPassword, $this->dbName);
            if($conn->connect_error){
                die("Failed to connect with MySQL: " . $conn->connect_error);
            }else{
                $this->db = $conn;
            }
        }
	}
	function getRows(){
		$idimovel   = $_GET["idimovel"];
		$query = $this->db->query("SELECT * FROM tour WHERE imovel_id =".$idimovel." ORDER BY ordem ASC");
		if($query->num_rows > 0){
			while($row = $query->fetch_assoc()){
				$result[] = $row;
			}
		}else{
			$result = FALSE;
		}
		return $result;
	}
	
	function updateOrder($id_array){
		$count = 1;
		foreach ($id_array as $id){
			$update = $this->db->query("UPDATE tour SET ordem = $count WHERE idtour = $id");
			$count ++;	
		}
		return TRUE;
	}
}
?>