<?php

/*
 *      ClaseBD.php
 *
 *      adaptacion Clase para gestion de bases de datos, soporta;
 *      MySQL
 *      
 *      Copyright 2008 Juan Angelo Iturra Echeverría <jaiturrae@gmail.com>
 *      
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 *      
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *      
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 *      MA 02110-1301, USA.
 */
class Base_Datos{
    
    var $nombre;
    var $host;
    var $user;
    var $passwd;
    var $port;
    var $conector;
    var $sql_error;
    
    function Base_Datos($bd_nombre="",$bd_host="",$bd_user="",$bd_passwd="",$bd_port=""){
	
	$this->nombre = $bd_nombre;
        $this->host = $bd_host;
        $this->user = $bd_user;
        $this->passwd = $bd_passwd;
        $this->port = $bd_port;
	$this->sql_error = null;
		
	// Conectar a Base de Datos
	$this->Conectar();
	//$this->conector = $conexion;
	
    }
    
    function Conectar(){
	
	$this->conector = @mysql_connect($this->host,$this->user,$this->passwd)
	or die("<div class='error'>No se puede conectar con host {$this->host}</div>\n");
	
	@mysql_select_db($this->nombre,$this->conector) 
	or exit("<div class='error'>No se puede seleccionar base de datos {$this->nombre}</div>");
	
    }
    
    function ConsultaSQL( $sql = null ){
	
        return mysql_query($sql, $this->conector);
        
    }
    
    function enArray( $vresult = null ){
        
	return mysql_fetch_array($vresult);
        
    }
    
    function TotalReg( $tabla = null ){
	
	return @mysql_fetch_assoc(@mysql_query("SELECT COUNT(id) AS total FROM {$tabla}",$this->conector));
	
    }
    
    function CerrarConexion(){
	
	mysql_close($this->conector);
	
    }
}

?>