<?php

if (!isset($_SESSION)) { session_start(); }

class database {

  private $conexion;

  public function conectar(){
           
         if(!isset($this->conexion)){ 

              $this->conexion = new mysqli($_SESSION['servidor'],$_SESSION['usuario'],$_SESSION['password'],$_SESSION['nombre_bd']); 
      
              if ($this->conexion->connect_errno) {
                    echo "Error de Conexi&oacute;n";
                    exit;
              }


          }
  }

//---------------------------------
 
public function consulta($sql){
                 
   $resultado =$this->conexion->query($sql); 
      
      if(!$resultado){
            echo 'Error: '.$sql. $this->conexion->connect_errno;
            exit;
       }
   
      return $resultado;
}

//----------------------------------

function numero_de_filas($result){
      return $result->num_rows;
}

//----------------------------------

function fetch_assoc($result){
         return $result->fetch_assoc();
}

//----------------------------------

public function disconnect(){
       mysqli_close($this->conexion);
}
  
}
?>