<?php
require_once 'pdoparameters.php';
/*
*@Autor DNDSIT 
*/
class PDOCONTROLLER{
	/*private $cadenaconex;
	private $conex;
	
	public function __construct(){
		$conex = $this->connectDB();
		if(!empty($conex)) {
			$this->conex = $conex;			
		}
		
	}

	function connectDB() {
		try{
			$this->cadenaconex="mysql:host=".DB_SERVER.";port=".DB_PORT.";dbname=".DB_DBNAME.";charset=".DB_CHARSET;
			$options=[
				PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
				PDO::ATTR_EMULATE_PREPARES => false,
			];
			$pdo = new PDO($this->cadenaconex,DB_USER,DB_PASS,$options);
			return $pdo;

		}catch(Exception $ex){
			echo "Error conexions".$ex->getMessage();
			exit;
		}

	}*/

	private $cadenaconex;
	private $conex;
	private $host = "69.197.152.107";
	private $port = "3306";
	private $user = "usufe";
	private $password = "Naty@2012*";
	private $database = "dnd";
	private $charset ="utf8";

	public function __construct(){
		$conex = $this->connectDB();
		if(!empty($conex)) {
			$this->conex = $conex;			
		}
	}
	function connectDB() {
		try{
			$this->cadenaconex="mysql:host=".$this->host.";port=".$this->port.";dbname=".$this->database.";charset=".$this->charset;
			$options=[
				PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
				PDO::ATTR_EMULATE_PREPARES => false,
			];
			$pdo = new PDO($this->cadenaconex,$this->user,$this->password,$options);
			return $pdo;
		}catch(Exception $ex){
			echo "Error conexions".$ex->getMessage();
			exit;
		}
	}
	

	public function executeconsulta($sql="",$valores=array()){
		if($sql != "" && strlen($sql)>0){
			
			//echo json_encode($valores);
			try{
				$consulta=$this->conex->prepare($sql);
				//$consulta = $this->$conex->query($sql);
				$consulta->execute($valores);
				if(intval($consulta->errorCode())===0){
					return $consulta->fetchAll(PDO::FETCH_ASSOC);
				}else{
					return intval($consulta->errorCode());
				}
			}catch(exception $ex){
				return $ex->getMessage();
			}
		}else{
			echo "else";
			return 0;
		}
	}

	public function execute_update($sql="",$valores=array()){
		if($sql != "" && strlen($sql)>0){
			try{
				$update=$this->conex->prepare($sql);
				$update->execute($valores);
				return $update->rowCount();
				
			}catch(exception $ex){
				return $ex->getMessage();
			}
		}else{
			echo "else";
			return 0;
		}
	}

	public function execute_insert($sql="",$valores=array()){
		if($sql != "" && strlen($sql)>0){
			try{
				$insert=$this->conex->prepare($sql);
				$insert->execute($valores);
				$idinsert=$this->conex->lastInsertId();
				return $idinsert;
			}catch(exception $ex){
				return $ex->getMessage();
			}
		}else{
			echo "else";
			return 0;
		}
	}


}

class PDOECOSCORP{
	private $cadenaconex;
	private $conex;
	private $host = "69.197.152.107";
	private $port = "3306";
	private $user = "usufe";
	private $password = "Naty@2012*";
	private $database = "ecos_corp";
	private $charset ="utf8";

	public function __construct(){
		$conex = $this->connectDB();
		if(!empty($conex)) {
			$this->conex = $conex;			
		}
	}
	function connectDB() {
		try{
			$this->cadenaconex="mysql:host=".$this->host.";port=".$this->port.";dbname=".$this->database.";charset=".$this->charset;
			$options=[
				PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
				PDO::ATTR_EMULATE_PREPARES => false,
			];
			$pdo = new PDO($this->cadenaconex,$this->user,$this->password,$options);
			return $pdo;
		}catch(Exception $ex){
			echo "Error conexions".$ex->getMessage();
			exit;
		}
	}
	

	public function executeconsulta($sql="",$valores=array()){
		if($sql != "" && strlen($sql)>0){
			try{
				//echo $sql;
				$consulta=$this->conex->prepare($sql);
				$consulta->execute($valores);
				if(intval($consulta->errorCode())===0){
					return $consulta->fetchAll(PDO::FETCH_ASSOC);
				}else{
					return intval($consulta->errorCode());
				}
			}catch(exception $ex){
				return $ex->getMessage();
			}
		}else{
			echo "else";
			return 0;
		}
	}

	public function execute_insert($sql="",$valores=array()){
		if($sql != "" && strlen($sql)>0){
			try{
				$insert=$this->conex->prepare($sql);
				$insert->execute($valores);
				$idinsert=$this->conex->lastInsertId();
				return $idinsert;
			}catch(exception $ex){
				return $ex->getMessage();
			}
		}else{
			echo "else";
			return 0;
		}
	}

	public function execute_update($sql="",$valores=array()){
		if($sql != "" && strlen($sql)>0){
			try{
				$update=$this->conex->prepare($sql);
				$update->execute($valores);
				return $update->rowCount();
				
			}catch(exception $ex){
				return $ex->getMessage();
			}
		}else{
			echo "else";
			return 0;
		}
	}


	public function execute_eliminar($sql="",$valores=array()){
		if($sql != "" && strlen($sql)>0){
			try{
				$elimina=$this->conex->prepare($sql);
				$elimina->execute($valores);
				return "procesado";
			}catch(exception $ex){
				return $ex->getMessage();
			}
		}else{
			echo "else";
			return 0;
		}
	}
}

class PDOECOS{
	private $cadenaconex;
	private $conex;
	private $host = "66.70.255.14";
	private $port = "3306";
	private $user = "apli_edu_ecos";
	private $password = "ZC2KlhsjTqGi";
	private $database = "apli_edu_ecos";
	private $charset ="utf8";

	public function __construct(){
		$conex = $this->connectDB();
		if(!empty($conex)) {
			$this->conex = $conex;			
		}
	}
	function connectDB() {
		try{
			$this->cadenaconex="mysql:host=".$this->host.";port=".$this->port.";dbname=".$this->database.";charset=".$this->charset;
			$options=[
				PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
				PDO::ATTR_EMULATE_PREPARES => false,
			];
			$pdo = new PDO($this->cadenaconex,$this->user,$this->password,$options);
			return $pdo;
		}catch(Exception $ex){
			echo "Error conexions".$ex->getMessage();
			exit;
		}
	}
	

	public function executeconsulta($sql="",$valores=array()){
		if($sql != "" && strlen($sql)>0){
			try{
				$consulta=$this->conex->prepare($sql);
				$consulta->execute($valores);
				if(intval($consulta->errorCode())===0){
					return $consulta->fetchAll(PDO::FETCH_ASSOC);
				}else{
					return intval($consulta->errorCode());
				}
			}catch(exception $ex){
				return $ex->getMessage();
			}
		}else{
			echo "else";
			return 0;
		}
	}

	public function execute_insert($sql="",$valores=array()){
		if($sql != "" && strlen($sql)>0){
			try{
				$insert=$this->conex->prepare($sql);
				$insert->execute($valores);
				$idinsert=$this->conex->lastInsertId();
				return $idinsert;
			}catch(exception $ex){
				return $ex->getMessage();
			}
		}else{
			echo "else";
			return 0;
		}
	}

	public function execute_update($sql="",$valores=array()){
		if($sql != "" && strlen($sql)>0){
			try{
				$update=$this->conex->prepare($sql);
				$update->execute($valores);
				return $update->rowCount();
				
			}catch(exception $ex){
				return $ex->getMessage();
			}
		}else{
			echo "else";
			return 0;
		}
	}


	public function execute_eliminar($sql="",$valores=array()){
		if($sql != "" && strlen($sql)>0){
			try{
				$elimina=$this->conex->prepare($sql);
				$elimina->execute($valores);
				return "procesado";
			}catch(exception $ex){
				return $ex->getMessage();
			}
		}else{
			echo "else";
			return 0;
		}
	}
}

?>