2017-12-02 00:27:32 +00:00
|
|
|
<?php
|
|
|
|
class DB{
|
|
|
|
private $pdo;
|
|
|
|
|
2017-12-08 14:08:12 +00:00
|
|
|
public function __construct($dbpdo){
|
2017-12-06 23:43:53 +00:00
|
|
|
$this->pdo = $dbpdo;
|
2017-12-01 16:58:33 +00:00
|
|
|
}
|
2017-12-02 00:27:32 +00:00
|
|
|
|
|
|
|
public function schema($schema_file){
|
|
|
|
$sql = file_get_contents($schema_file);
|
|
|
|
$this->pdo->exec($sql);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function insert($registro){
|
|
|
|
$columns = implode(",", array_keys($registro));
|
|
|
|
echo $columns;
|
|
|
|
$sql = "INSERT INTO Registro ($columns)"
|
|
|
|
.' VALUES (:nombre,:apellido,:titulo,:afiliacion,:ciudad,:pais,:email,:fechaLlegada,'
|
|
|
|
.':fechaPartida,:financiacion,:invitado,:cartaInvitacion,:roomingPref,:roommate,:fechaRegistro);';
|
|
|
|
echo $sql;
|
|
|
|
$stmt = $this->pdo->prepare($sql);
|
|
|
|
$stmt->execute([
|
|
|
|
':nombre' => $registro['nombre'],
|
|
|
|
':apellido' => $registro['apellido'],
|
|
|
|
':titulo' => $registro['titulo'],
|
|
|
|
':afiliacion' => $registro['afiliacion'],
|
|
|
|
':ciudad' => $registro['ciudad'],
|
|
|
|
':pais' => $registro['pais'],
|
|
|
|
':email' => $registro['email'],
|
|
|
|
':fechaLlegada' => $registro['fechaLlegada'],
|
|
|
|
':fechaPartida' => $registro['fechaPartida'],
|
|
|
|
':financiacion' => $registro['financiacion'],
|
|
|
|
':invitado' => $registro['invitado'],
|
|
|
|
':cartaInvitacion' => $registro['cartaInvitacion'],
|
|
|
|
':roomingPref' => $registro['roomingPref'],
|
|
|
|
':roommate' => $registro['roommate'],
|
|
|
|
':fechaRegistro' => $registro['fechaRegistro']
|
|
|
|
]);
|
|
|
|
return $this->pdo->lastInsertId();
|
|
|
|
|
2017-12-01 16:58:33 +00:00
|
|
|
}
|
2017-12-02 00:27:32 +00:00
|
|
|
public function getAll(){
|
|
|
|
$stmt = $this->pdo->prepare("SELECT * FROM Registro");
|
|
|
|
$stmt -> execute();
|
|
|
|
return $stmt->fetchAll(\PDO::FETCH_BOTH);
|
|
|
|
|
|
|
|
}
|
2017-12-06 23:43:53 +00:00
|
|
|
}
|
2017-12-01 16:58:33 +00:00
|
|
|
?>
|
|
|
|
|