<?php 
class Anuncio{
	public $conn;
	public $table_name="anuncios";

	public $id;
	public $id_estados;
	public $id_ciudades;
	public $titulo;
	public $descripcion;
	public $keywords;
	public $giros;
	public $telefono;
	public $movil;
	public $fax;
	public $nextel;
	public $id_nextel;
	public $email;
	public $direccion;
	public $url;
	public $cupon;
	public $vip;
	public $longitud;
	public $latitud;
	public $contrato;
	public $destacado;
	public $anunciosyoutube;
	public $anuncioshorario;
	public $anunciosusuario;
	public $anunciosUsuarioMail;
	public $anunciosUsuarioPassword;
	

	public function __construct($db){
		$this->conn=$db;
	}

	function select($consulta){
			$query=$consulta;
			$stmt = $this->conn->prepare($query);
			$stmt->bindParam(1,$anio);
			$stmt->execute();
			return $stmt;
		}

	function read(){
		 
		 $consulta="select * from ".$this->table_name." ORDER BY id DESC limit 20";
		 	
		    // prepare query statement
		    $stmt = $this->conn->prepare($consulta);
		    // execute query
		    $stmt->execute();
		 
		    return $stmt;

		}

	function Insert($stmt){
		try{
			$this->conn->beginTransaction();
			if($stmt->execute()){
				$id = $this->conn->lastInsertId("id");
				$this->conn->commit();
				return $id;
			}
		}catch(PDOExecption $e){
			$this->conn->rollback();
		}
		return false;
	}

	function Update($stmt){
		try{
			$this->conn->beginTransaction();
			if($stmt->execute()){
				
				$this->conn->commit();
				return true;
			}
		}catch(PDOExecption $e){
			$this->conn->rollback();
		}
		return false;
	}

    
	function delete(){
			$query="DELETE FROM ". $this->table_name." WHERE id=?";
			$stmt = $this->conn->prepare($query);
			$stmt->bindParam(1,$this->id);
			if($stmt->execute()){
				return true;
			}
			return false;
		}
}
?>