<?php
class dbmy {
var $server;
var $database;
var $user;
var $password;
var $myrs;
var $last_sql;
var $numrows;
var $numfields;
var $Conn;

function dbmy() {
  try {
    $this->server='localhost';
    $this->database='pregrado_pregrado';
    $this->user='pregrado_dbm';
    $this->password='2PN2QDmP6ZsHrcue';
    $this->Conn=mysql_connect($this->server,$this->user,$this->password);
    if (!$this->Conn){
      throw new Exception(mysql_error());
    } else {
      mysql_select_db($this->database);
      mysql_query ("SET NAMES 'utf8'");
    }
  } catch (Exception $e) {
    throw new Exception($e->getMessage());
  }
}

function EjecutarQuery($sql) {
  try {
    $this->myrs=mysql_query($sql,$this->Conn) or die ('Invalid query: '. $sql);
    if (!$this->myrs) {
      echo mysql_errno().": ".mysql_error()."<BR>";
      $this->numrows=0;
      $this->numfields=0;
    } else {
      $this->numrows=mysql_num_rows($this->myrs);
      $this->numfields=mysql_num_fields($this->myrs);
    }
    $this->last_sql=$sql;
  } catch (Exception $e) {
    throw new Exception($e->getMessage());
  }
}

function EjecutarTran($sql) {
  try {
    return mysql_query($sql,$this->Conn) or die ('Invalid query');
  } catch (Exception $e) {
    throw new Exception($e->getMessage());
  }
}

function DataObjeto() {
  try {
    if (!$this->myrs) { //deberia ir a un log de errores global
      $ret=null;
    } else {
      $ret=mysql_fetch_object($this->myrs);
    }
    return $ret;
  } catch (Exception $e) {
    throw new Exception($e->getMessage());
  }
}
function DataArray() {
  try {
    if (!$this->myrs) { //deberia ir a un log de errores global
      $ret=null;
    } else {
      $ret=mysql_fetch_assoc($this->myrs);
    }
    return $ret;
  } catch (Exception $e) {
    throw new Exception($e->getMessage());
  }
}
/*
function DataFechArray() {
  try {
    if (!$this->myrs) { //deberia ir a un log de errores global
      $ret=null;
    } else {
      $ret=mysql_fetch_array($this->myrs);
    }
    return $ret;
  } catch (Exception $e) {
    throw new Exception($e->getMessage());
  }
}*/

function count() {
  return $this->numrows;
}
function fldinf($i) {
  try {
    if (!$this->myrs) { //deberia ir a un log de errores global
      $ret=null;
    } else {
      $campos['name'] = mysql_field_name($this->myrs, $i);
      $campos['type'] = mysql_field_type($this->myrs, $i);
      $campos['len']  = mysql_field_len($this->myrs, $i);
	  $campos['flags']  =mysql_field_flags($this->myrs, $i);


      $ret=$campos;
    }
    return $ret;
  } catch (Exception $e) {
    throw new Exception($e->getMessage());
  }
}
function numfld() {
  return $this->numfields;
}
function movefirst() {
  try {
    mysql_data_seek($this->myrs,0);
  } catch (Exception $e) {
    throw new Exception($e->getMessage());
  }
}

function movemyr($pos) {
  try {
    mysql_data_seek($this->myrs,$pos);
  } catch (Exception $e) {
    throw new Exception($e->getMessage());
  }
}
}
?>
