<?php

class DB{
	//database configuration
	private $dbHost     = "localhost";
	private $dbUsername = "construm_lote";
	private $dbPassword = "TY5+w35n,IWR";
	private $dbName     = "construm_lote";
	private $imgTbl     = 'slide_empreendimentos';
	 
	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 slide_empreendimentos 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 slide_empreendimentos SET ordem = $count WHERE idslide_empreendimentos = $id");
			$count ++;	
		}
		return TRUE;
	}
}
?>