Files
prueba-aplicaciones-web/models/alumno.php
Daniel Cortés f480b2942f initial commit
2019-12-12 16:05:20 -03:00

47 lines
1.2 KiB
PHP

<?php
require_once('../db.php');
class Alumno
{
private $id;
private $rut;
private $nombre;
public function __construct() {}
public function set_id($id) { $this->id = $id; }
public function get_id() { return $this->id; }
public function set_rut($rut) { $this->rut = $rut; }
public function get_rut() { return $this->rut; }
public function set_nombre($nombre) { $this->nombre = $nombre; }
public function get_nombre() { return $this->nombre; }
public function save()
{
$db = new DB();
$result = $db->dml
(
"insert into alumno (rut, nombre) values (?, ?)",
$this->rut, $this->nombre
);
return $result > 0;
}
public static function getAll() {
$db = new DB();
$results = $db->query("select * from alumno");
$alumnos = [];
foreach($results as $result) {
$alumno = new Alumno();
$alumno->set_id($result['id']);
$alumno->set_rut($result['rut']);
$alumno->set_nombre($result['nombre']);
array_push($alumnos, $alumno);
}
return $alumnos;
}
}
?>