🌹🏠🌹？》《》？《》？<?php

if(file_exists(dirname(__DIR__) . '/../vendor/autoload.php')) {
    require_once dirname(__DIR__) . '/../vendor/autoload.php';
    $dotenv = Dotenv\Dotenv::createImmutable(dirname(__DIR__) .'/../');
    $dotenv->load();
}

class Base extends GLSA
{
public $conexion;
public $error = 0; // falso // 1: no esta // 2 : error sintaxis.
public $msg_error;
public $row;
public $base_web;
public $base_ec;
public $tipo_base; // I informix - S: sql server

function __construct()
{

$this->tipo_base = getenv("DB_TYPE");
$this->base_web = getenv('DB_BASE_WEB');
$this->base_wms = getenv('DB_BASE_WMS');
$p_dns   = getenv("DB_GLSA_HOST");
$p_user  = getenv("DB_GLSA_USER");
$p_clave = getenv("DB_GLSA_PASSWORD");



if (!($link=@odbc_connect($p_dns,$p_user,$p_clave))){
  $this->conexion = false;
  $this->error    = 1;
  $this->msg_error= "01- Error. No se pudo conectar con la BD !! ";
}
else  {
  $this->conexion=$link;
}
}

function r_cuenta($r_consulta)
{  
$resultado=@odbc_exec($this->conexion,$r_consulta);
if (!$resultado) {
  $er=odbc_errormsg($this->conexion);
  die ($er);
}
$cuenta = 0;
while ($fila = odbc_fetch_array($resultado)){
    $cuenta++;
}
  
return $cuenta;
}

function r_select_fila($r_consulta,$r_tabla='')
{
$this->error = 0;
$this->msg_error = "";
$resultado=@odbc_exec($this->conexion,$r_consulta);
if (!$resultado){
  $this->error     = 2;
  $this->msg_error = "04- Error. No se pudo leer [$r_tabla] !! ";
  return;
}
$row=odbc_fetch_array($resultado);
if (!$row){
  $this->error     = 1;
  $this->msg_error = "05- Error. No se pudo leer [$r_tabla] !! ";
  return;
}
$this->row = $row;
odbc_free_result($resultado);

return;
}  

function r_exec_gral($r_consulta,$r_tabla='')
{
$this->error = 0;
$this->msg_error = "";
$resultado=@odbc_exec($this->conexion,$r_consulta);
if (!$resultado){
  $this->error     = 1;
  $this->msg_error = "06- Error. No se pudo ejecutar [$r_tabla] !! ";
  return;
}
odbc_free_result($resultado);

}

function r_exec($r_consulta,$r_tabla='',$r_cuantos)
// cuantos -1 puede no borar ninguno. 0 varios - 1 solo 1
{
$this->error = 0;
$this->msg_error = "";
$resultado=@odbc_exec($this->conexion,$r_consulta);
if (!$resultado){
  $this->error     = 1;
  $this->msg_error = "07- Error. No se pudo ejecutar [$r_tabla] !! ";
  return;
}
switch ($r_cuantos) {
  case -1:
    break;
  case 0:
    if (odbc_num_rows($resultado) <= $r_cuantos ){
      $this->error     = 1;
      $this->msg_error = "08- Error. No se pudo ejecutar [$r_tabla] !! ";
    }
    break; 
  default:
    if (odbc_num_rows($resultado) != $r_cuantos ){
      $this->error     = 1;
      $this->msg_error = "09- Error. No se pudo ejecutar [$r_tabla] !! ";
    }
    break;
}
odbc_free_result($resultado);

}

function r_begin_trans()
{

$this->error = 0;
$this->msg_error = "";
$sql="begin tran";
$resultado=@odbc_exec($this->conexion,$sql);
if (!$resultado){
   $this->error     = 1;
   $this->msg_error = "10- Error. Begin Transaccion !! ";
   return;
}
odbc_free_result($resultado);

}

function r_end_trans()
{

$this->error = 0;
$this->msg_error = "";
$sql="commit tran";
$resultado=@odbc_exec($this->conexion,$sql);
if (!$resultado){
   $this->error     = 1;
   $this->msg_error = "11- Error. Commit Transaccion !! ".$sql;
   return;
}
odbc_free_result($resultado);

}

function r_rollback_trans()
{

$this->error = 0;
$this->msg_error = "";

$sql="rollback tran";
$resultado=@odbc_exec($this->conexion,$sql);
if (!$resultado){
   $this->error     = 1;
   $this->msg_error = "12- Error. Rollback Transaccion !! ";
   return;
}
odbc_free_result($resultado);

}

function r_insert($r_tabla,$r_campos) 
{
$p_cancel=false;
}

function __destruct()
{
  //odbc_close($this->conexion);
}

}

?>