<?php
class Access_clsConexion{
    private $pServer;
    private $pDatabase;
    private $pUser;
    private $pPassword;
    private $pPort;
    
    function __construct(){ 
        $this->pServer="localhost";
        $this->pDatabase="infope_pts2";
        $this->pUser="infope_upts2";
        $this->pPassword="gigi240602";
        $this->pPort="5432";
    }
    function Connect(){
        $myConnect=false;
        try{
            $myConnect=new PDO('pgsql:host='.$this->pServer.' port='.$this->pPort.' dbname='.$this->pDatabase.' user='.$this->pUser.' password='.$this->pPassword);
        } catch (PDOException $e){
            echo "Error en la conexion".$e->getMessage();
        }
        return $myConnect;
    }

    function Ejecutar_SQL($strQuery){
        try{
            $oConnect=$this->Connect();
            if($oConnect){
                return $oConnect->query($strQuery);
            }else return false;
        } catch (PDOException $e){
            return false;
        }
    }
    function Ejecutar_Consulta($strQuery){
        try{
            $oConnect=$this->Connect();
            if($oConnect){
                $rs=$oConnect->query($strQuery);
                if ($rs) return $rs;
                else return false;
            }return false;
        } catch (PDOException $e){
            return false;
        }
    }

    function Escapar_Caracteres($vCadena){
        if (get_magic_quotes_gpc()){
            $vCadena=stripslashes($vCadena);
        }
        return pg_escape_string($vCadena);
    }
    function Ejecutar_SQL2($strQuery){
        try{
            $oConnect=$this->Connect();
            if($oConnect){
                $rsOut=$oConnect->query($strQuery);
                if ($rsOut){
                    return $rsOut->fetch(PDO::FETCH_ASSOC);
                }else{
                    $rowError=$oConnect->errorInfo();
                    $rowOut['outstate']=0;
                    $rowOut['outid']=0;
                    $rowOut['outerrornumber']=intval($rowError[1]);
                    $rowOut['outdescription']=$rowError[2];
                    return $rowOut;
                }
            }else{
                $rowOut['outstate']=0;
                $rowOut['outid']=0;
                $rowOut['outerrornumber']="9999";
                $rowOut['outdescription']="Error de conexion a la base de datos.";
                return $rowOut;
            }
        } catch (PDOException $e){
            $rowOut['outstate']=0;
            $rowOut['outid']=0;
            $rowOut['outerrornumber']="9998";
            $rowOut['outdescription']="Error interno";
            return $rowOut;
        }
    }
    function __destruct(){
        //$this->miConexion=null;
    }
}
?>
