<?php 
ini_set('display_errors','On');
require_once($_SERVER['DOCUMENT_ROOT'].'/shine/datos/clsConexion.php');
class Query extends Conexion
	{
		var $sql		= NULL;
		var $msj_query	= NULL;
		var $result		= NULL;
		
		function __construct()  {
			parent::__construct();
			parent::MET_conectar();
		}  // end __construct
		
		function __get($atributo)  {
			$cad = '$aux = $this->'.$atributo.';';
			eval ($cad);
			return $aux;
		} // end __get
		
		function __set($atributo, $valor) {
			$cad = '$this->'.$atributo." = '$valor';";
			eval ($cad);
		} // end __set
		
		function MET_Select()  {
			$this->result=mysqli_query($this->cnx, $this->sql);
//			echo $this->sql;exit;
			if(!$this->result)  { 
				$this->msj_query="Error: ".mysqli_errno($this->cnx). " en Select: ".mysqli_errno($this->cnx);
				echo($this->msj_query);
				print_r($this->result);exit;

				return false;
			} // end if
			
			if(mysqli_num_rows($this->result) <= 0)  {
				$this->msj_query="No existen datos a consultar";
				return false;
			} // end if
			while ($reg = mysqli_fetch_assoc($this->result))  {
				$registros[] = $reg;  // genera arreglo multidimensional
			} // end while
//			print_r($reg);exit;
//			print_r($registros);exit;
			return $registros;
		
		} // end MET_Select

		function MET_SelectOne()  {
			$this->result=mysqli_query($this->cnx, $this->sql);
			
			if(!$this->result)  { 
			echo $this->sql;exit;
	//		echo mysql_error();exit;
				$this->msj_query="Error: ".mysqli_errno($this->cnx). " en Select: ".mysqli_errno($this->cnx);
				return false;
			} // end if
			
			if(mysqli_num_rows($this->result) <= 0)  {
				$this->msj_query="No existen datos a consultar";
				return false;
			} // end if
//			echo $this->msj_query;exit;
			$reg = mysqli_fetch_assoc($this->result);
			return $reg;
		} // end MET_SelectOne

		function MET_Insert()  {
			$this->result=mysqli_query($this->cnx, $this->sql);
//			echo $this->sql;exit;
			if(!$this->result) { 
				$this->msj_query="Error: ".mysql_errno($this->cnx). " en Insert: ".mysql_errno($this->cnx);
				return false;
			}
			
			if(mysqli_affected_rows($this->cnx) <= 0)  {
				$this->msj_query="No se insertaron los datos";
				return false;
			}
			$this->msj_query="se insertaron los datos";
			return true;
		} // end Insert


		function MET_Update()  {
			$this->result=mysqli_query($this->cnx, $this->sql);
			if(!$this->result)  {
				$this->msj_query="Error: ".mysqli_errno($this->cnx). ": ".mysqli_error($this->cnx);
				return false;
			} // end if
			
			if(mysqli_affected_rows($this->cnx) <= 0)  {
				$this->msj_query = "No se modificaron los datos";
				return false;
			} // end if
			$this->msj_query = "se modificaron los datos";
			return true;
		} // end Update
		
		function MET_delete()  {
//			echo $this->sql;exit;
			$this->result=mysql_query($this->sql,$this->cnx);
//			print_r($this->result);exit;
			if(!$this->result)  {
				$this->msj_query = "Error: ".mysql_errno(). " en Delete: ".mysql_errno();
//				echo $this->msj_query;exit;
				return false;
			}
			
			if(mysql_affected_rows($this->cnx) <= 0)  {
				$this->msj_query = "No se eliminaron los datos";
				//echo $this->msj_query;				exit;
				return false;
//				
			}
			$this->msj_query = "se eliminaron los datos";
			//				echo $this->msj_query;exit;
			return true;
		}
	
	}
?>