-
-
Save parzibyte/2259951716d30ea8bde6836c3b63e108 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function actualizarProducto($nombre, $precio, $descripcion, $id) | |
{ | |
$bd = obtenerConexion(); | |
$sentencia = $bd->prepare("UPDATE productos SET nombre = ?, precio = ?, descripcion = ? WHERE id = ?"); | |
return $sentencia->execute([$nombre, $precio, $descripcion, $id]); | |
} | |
function obtenerProductoPorId($id) | |
{ | |
$bd = obtenerConexion(); | |
$sentencia = $bd->prepare("SELECT id, nombre, descripcion, precio FROM productos WHERE id = ?"); | |
$sentencia->execute([$id]); | |
return $sentencia->fetchObject(); | |
} | |
function obtenerProductos() | |
{ | |
$bd = obtenerConexion(); | |
$sentencia = $bd->query("SELECT id, nombre, descripcion, precio FROM productos"); | |
return $sentencia->fetchAll(); | |
} | |
function eliminarProducto($id) | |
{ | |
$bd = obtenerConexion(); | |
$sentencia = $bd->prepare("DELETE FROM productos WHERE id = ?"); | |
return $sentencia->execute([$id]); | |
} | |
function guardarProducto($nombre, $precio, $descripcion) | |
{ | |
$bd = obtenerConexion(); | |
$sentencia = $bd->prepare("INSERT INTO productos(nombre, precio, descripcion) VALUES(?, ?, ?)"); | |
return $sentencia->execute([$nombre, $precio, $descripcion]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment