ok pero no creo q eso sea ahi va...
Código PHP:
<?php
include_once 'base.php';
class table
{
public $table_name;
private $base=null;
private $campos = array();
public $rs=null;
//********************************************************
public function __construct($table='', $base=null)
{
$this->table_name = $table;
$this->base = &$base;
}
//********************************************************
public function __set($name, $value)
{
$this->campos[$name] = $value;
}
//*********************************************************
public function __get($name)
{
$ret = null;
if (array_key_exists($name, $this->campos))
$ret = $this->campos[$name];
if ($name == 'RecordCount')
{if ($this->rs)
$ret = $this->rs->RecordCount();
else
$ret = -1;
}
if ($name == 'Registro')
$ret = $this->campos;
return $ret;
}
//********************************************************
private function GetFields() // doesn´t work with empty table
{
$sql = "select * from {$this->table_name}";
$rs = $this->base->dosql_limit($sql, 1);
return $rs->fields;
}
//********************************************************
public function AutoLoadFields()
{
$this->campos = $this->GetFields();
}
//********************************************************
function Save()
{
$this->base->Insert($this->table_name, $this->campos);
}
//********************************************************
function AssignFields($valores) // Asigna un arreglo de campos
{
$campos = $this->GetFields();
foreach($valores as $key => $val)
{
if (array_key_exists($key, $campos))
$registro[$key]=$val;
}
// var_dump($registro);
$this->campos = $registro;
}
//********************************************************
function SaveArray($valores) // recibe arregelo de campos y los almacena en la tabla
{
$this->AssignFields($valores);
$this->Save();
}
//********************************************************
function Update($where=false)
{
$this->base->Update($this->table_name, $this->campos,'UPDATE', $where);
}
//********************************************************
function InsUpd($key='', $autoquote=false)
{
if ($key == '') $key = $campos[0]; // primer campo id por defecto
$this->base->InsUpd($this->table_name, $this->campos, $key, $autoquote);
}
//********************************************************
function Select($campos='', $where='', $orderfield='')
{
if ($where != '') $where = " where $where";
if ($orderfield != '') $orderfield = " order by $orderfield";
$sql = "select $campos from {$this->table_name} $where $orderfield";
$this->rs = $this->base->dosql($sql);
if ($this->rs)
$this->campos = $this->rs->fields;
return($this->rs);
}
//********************************************************
function Find($valor, $campo_where='') // por defecto busca por la llave primaria
{
if ($campo_where == '') $campo_where = $this->base->GetPK($this->table_name);
return $this->Select('*', "$campo_where = '$valor' ");
}
//********************************************************
function Delete($valor, $campo_where='') // por defecto borra por la llave primaria
{
$res = false;
if ($this->Find($valor, $campo_where))
{$res = true;
if ($campo_where == '') $campo_where = $this->base->GetPK($this->table_name);
while(!$this->rs->EOF)
{
$val_campo = $this->rs->fields[$campo_where];
$sql = "delete from {$this->table_name} where $campo_where = $val_campo";
$this->base->dosql($sql);
$this->rs->MoveNext();
}
}
return($res);
}
//********************************************************
function GetCombo($name, $id='', $valor='', $defa='')
{$cam = $this->campos;
reset($cam); // echo '-->'.key($cam);
if ($id == '')
{$id = key($cam); next($cam);}
if ($valor == '') $valor = key($cam);
// var_dump($id); var_dump($valor);
while(!$this->rs->EOF)
{ $key = $this->rs->fields[$id];
$val = $this->rs->fields[$valor];
$opt .= "<option value = \"$key\">$val</option>\n";
$this->rs->MoveNext();
}
$res = "<select name=\"$name\">\n$opt\n</select>";
return($res);
}
//********************************************************
function ShowRecord()
{
echo "<pre>";
var_dump($this->campos);
echo "</pre>";
}
//********************************************************
function GetRows($field='')
{$res = '';
if (($this->rs == null) || (!is_array($this->campos))) return('');
if ($field == '') $field = key(($this->campos));
while(!$this->rs->EOF)
{ $res .= $this->rs->fields[$field]."<br/>\n";
$this->rs->MoveNext();
}
return($res);
}
//********************************************************
function Error()
{
return($this->base->ErrorNo() != 0);
}
//********************************************************
}
?>
y base anotador simplemente es la conexion a la BD