<?php

class Conexion {
    private $conexion;
   
    private $parametros = array();
    private $parametrosIn = array();
    private $values = array();
  
    //ok
    public function Conectar() {
        $server = '161.132.55.34';
        $this->conexion = mssql_connect($server, 'inkamed1_bdsistemaserviscomensales2', '46073651_Jf');
        mssql_select_db("inkamed1_bdsistemaserviscomensales", $this->conexion);
        if (!$this->conexion) {
            die('Error de conexión a MSSQL');
        }
    }

    //ok
    public function reiniciarArray(){
        $this->parametros = array();
        $this->parametrosIn = array();
        $this->values = array();
    }
    
    //ok
    public function Parametro($p1, $p2){
        array_push($this->parametros, $p1);
        array_push($this->parametrosIn, $p2);
        array_push($this->values, array(&$p2, SQLSRV_PARAM_IN));
    }
    
    //ok
    public function Procedimiento($nombre) {
        $sql = "EXEC ".$nombre." ";
        $es_pri = true;
        foreach($this->parametrosIn as &$data) {
            if ($es_pri)
                $es_pri = false;
            else
                $sql .= ',';
            $sql .= "'" . $data . "'";
        }
        $query = mssql_query($sql);
        $data1 = array();
        // Verifica si ha devuelto algún registro
        if (mssql_num_rows($query)) {
            while ($row = mssql_fetch_array($query)) {
                $data1[] = $row;
            }
        }
        mssql_free_statement($stmt);
        return $data1;
    }
    
    //ok
    public function Desconectar() {
        mssql_close($this->conexion);
    }
}
