Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mysqli_report(MYSQLI_REPORT_ERROR / MYSQLI_REPORT_STRICT);
- require "conexion_libreria.php";
- class Libreria extends ConexionLibreria {
- public function consultarLibros() {
- try {
- $sql ="SELECT * FROM libros ORDER BY titulo";
- $resultado = $this->conexionLibros->query($sql);
- $libros = $resultado->fetch_all(MYSQLI_ASSOC);
- return $libros;
- } catch (Exception $e) {
- throw new Exception("Hubo un error en el select: ".$e->getMessage());
- }
- }
- public function altaLibros($titulo, $precio) {
- try {
- $sql="INSERT INTO libros VALUES(NULL, '$titulo', '$precio')";
- $this->conexionLibros->query($sql);
- return "Alta efectuada";
- } catch (Exception $e) {
- if ($e->getCode()=='1062') {
- throw new Exception("Libro ya existe en la base de datos");
- } else {
- throw new Exception("Error en el alta: ".$e->getCode().'/'.$e->getFile().'/'.$e->getLine().'/'.$e->getMessage());
- }
- }
- }
- public function bajaLibros($id) {
- try {
- $sql="DELETE FROM libros WHERE idlibros='$id'";
- $this->conexionLibros->query($sql);
- return "Baja efectuada";
- } catch (Exception $e) {
- if ($e->getCode()=='1062') {
- throw new Exception("Libro no existe en la base de datos");
- } else {
- throw new Exception("Error en la baja: ".$e->getCode().'/'.$e->getFile().'/'.$e->getLine().'/'.$e->getMessage());
- }
- }
- }
- public function modificaLibros($id, $titulo, $precio) {
- try {
- $sql="UPDATE libros SET idlibros='$id', titulo='$titulo', precio='$precio' WHERE idlibros='$id'";
- $this->conexionLibros->query($sql);
- return "Modificación efectuada";
- } catch (Exception $e) {
- if ($e->getCode()=='1062') {
- throw new Exception("Libro no existe en la base de datos");
- } else {
- throw new Exception("Error en la modificación: ".$e->getCode().'/'.$e->getFile().'/'.$e->getLine().'/'.$e->getMessage());
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement