public function consulta_registro($where = null) { if (!$this->get_tabla()) { die("DB_info.consulta_registro dice:<br />No se ha seteado el nombre de la tabla"); } if ($where == null) { $where = $this->get_condicion(); } $tbl_arreglo = DB_Structure::get_campos_tabla($this->get_tabla()); if (stristr($where, "WHERE")) { $where = str_ireplace("WHERE", "", $where); } $sql = "SELECT " . DB_Structure::get_id($this->get_tabla()) . " FROM " . $this->get_tabla() . " WHERE " . $where; // debug( $sql ); if ($this->regCount($sql)) { $sql = "SELECT * FROM " . $this->get_tabla() . " WHERE " . $where; // debug( $sql, "Query de consulta" ); $registro = $this->get_registro($sql); foreach ($tbl_arreglo as $nombre) { $this->_campos_consultados[$this->get_tabla()][$this->get_id()][$nombre] = isset($registro->{$nombre}) ? $this->get_salto_de_linea() ? $this->get_utf8_string(nl2br($registro->{$nombre})) : $this->get_utf8_string($registro->{$nombre}) : false; } } else { foreach ($tbl_arreglo as $nombre) { $this->_campos_consultados[$this->get_tabla()][$this->get_id()][$nombre] = ""; } } }
public function get_ultimo_id() { $ultimo_id = $this->mysqli->insert_id; if (!$ultimo_id) { /* if( !$this->_objeto_referencia->get_nombre_campos( $this->_objeto_referencia->get_tabla() ) ) $this->_objeto_referencia->campos_consultados[$this->_objeto_referencia->get_tabla()] = DB_v3::get_cnx()->consulta_nombre_campos($this->_objeto_referencia->get_tabla()); $campo_unico = $this->_objeto_referencia->get_nombre_campos( $this->_objeto_referencia->get_tabla(), 0 ); */ $id_tabla = DB_Structure::get_id($this->_objeto_referencia->get_tabla()); $sql = "SELECT " . $id_tabla . " FROM " . $this->_objeto_referencia->get_tabla() . " ORDER BY " . $id_tabla . " DESC LIMIT 1"; $registro = $this->get_registro($sql); $ultimo_id = $registro->{$id_tabla}; } return $ultimo_id; }
/** * Permite eliminar el registro de una tabla * Ultima revision: 2012-03-28 * Reviso: Martin Tlapa * @param type $id * @return boolean */ function elimina() { if (!$this->get_tabla()) { die('DB_Crud.elimina() dice:<br />Falta definir el nombre de la tabla'); } if ($this->get_id()) { $this->set_cmd("deleted"); if ($this->get_custom_id()) { $id = $this->get_custom_id(); } else { $id = DB_Structure::get_id($this->get_tabla()); } if (!$this->get_ignorar_campos_control()) { $identifier = strtolower(substr($id, 0, 3)); $deletes[] = $identifier . "_eliminado = '" . $_SESSION[$this->__auth_nombre_id_usuario] . "'"; $deletes[] = $identifier . "_fecha_eliminado = NOW()"; $sql = "UPDATE " . $this->get_tabla() . " SET " . implode(", ", $deletes) . " WHERE " . $id . " = " . $this->get_id() . ";"; } else { $sql = "DELETE FROM " . $this->get_tabla() . " WHERE " . $id . " = " . $this->get_id() . ";"; } $this->execute($sql); return true; } else { $this->set_error("id_no_especificado"); $this->set_more_info("No se ha especificado el ID a eliminar"); } if ($this->get_error() && DB::$_file_log_name && DB::$_path_log) { $this->save_log("ERROR - DB_CRUD.elimina() dice: " . $this->get_error() . "\n" . $this->get_more_info()); } elseif ($this->get_error() && $this->get_debug_mode()) { die("ERROR - DB_CRUD.elimina() dice: " . $this->get_error() . "\n" . $this->get_more_info()); } return false; }