<?php
	class conexionDB{
		private $server,$name,$pass,$db;
		public $links;
		
		public function __construct(){
			include('configDb.php');//ARCHIVO DE CONFIGURACION
			
			$this->setServer($config['SERVIDOR']); // Nombre del servidor
			$this->setName($config['NOMBRE']);//nombre del usuario de la base de datos
			$this->setPass($config['CLAVE']);//clave de la base de datos
			$this->setDb($config['BASE_DATOS']);// nombre de la base de datos
			$this->setLink = false;
		}
		
		//SETTER's
		public function setServer($server){
			$this->server = $server;
		}
		
		public function setName($name){
			$this->name=$name;
		}
		
		public function setPass($pass){
			$this->pass=$pass;
		}
		
		public function setDb($db){
			$this->db= $db;
		}
		
		public function setLink($link){
			$this->links = $link;
		}
		
		
		//GETTERS
		public function getServer(){
			return $this->server;
		}
		
		public function getName(){
			return $this->name;
		}
		
		public function getPass(){
			return $this->pass;
		}
		
		public function getDb(){
			return $this->db;
		}
		
		public function getLink(){
			return $this->links;
		}
		
		
		//Conecta a la base de datos
		public function Conectar(){

			$this->setLink(mysql_connect($this->getServer(), $this->getName(), $this->getPass()));
			mysql_query("SET NAMES 'utf8'");
			if (!$this->getLink()){
				die ("No se puede conectar a MySQL");
			}else{
				$ok = mysql_select_db($this->getDb(),$this->getLink()) or die ("No se puede abrir la base de datos: ". mysql_errno($this->getLink()) . ": " . mysql_error($this->getLink()). "\n");	
				return $this->getLink();
			}
		}
		
		//CIERRO LA CONEXION A LA DB
		public function Desconectar(){
			mysql_close($this->getLink());
		}
	}
?>