public function engadirPacente($pacente, $idsServizos)
{
try {
$this->conexion->beginTransaction();
$sql = 'INSERT INTO pacentes (nome, email, nacemento, alta) VALUES (:nome, :email, :nacemento, :alta)';
$stm = $this->conexion->prepare($sql);
$stm->bindParam('nome', $pacente->nome);
$stm->bindParam('email', $pacente->email);
$stm->bindParam('nacemento', $pacente->nacemento);
$stm->bindParam('alta', $pacente->alta);
$stm->execute();
$idPacente = $this->conexion->lastInsertId();
$sqlPibote = 'INSERT INTO pacente_servizo (pacente_id, servizo_id) VALUES (:pacente_id, :servizo_id)';
$stmPibote = $this->conexion->prepare($sqlPibote);
foreach ($idsServizos as $id) {
$stmPibote->bindParam('pacente_id', $idPacente);
$stmPibote->bindParam('servizo_id', $id);
$stmPibote->execute();
}
$this->conexion->commit();
} catch (PDOException $e) {
$this->conexion->rollBack();
echo "Error para engadir o pacente: " . $e->getMessage();
}
}
public function borrarPacente($id)
{
try {
$this->conexion->beginTransaction();
$sqlPibote = 'DELETE FROM pacente_servizo WHERE pacente_id = :id';
$stmPibote = $this->conexion->prepare($sqlPibote);
$stmPibote->bindParam('id', $id);
$stmPibote->execute();
$sql = 'DELETE FROM pacentes WHERE id = :id';
$stm = $this->conexion->prepare($sql);
$stm->bindParam('id', $id);
$stm->execute();
$this->conexion->commit();
} catch (PDOException $e) {
$this->conexion->rollBack();
echo "Error para borrar o pacente: " . $e->getMessage();
}
}
}