Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created December 3, 2019 21:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/0d76555ca5e1c72e99bbcacd73047559 to your computer and use it in GitHub Desktop.
Save parzibyte/0d76555ca5e1c72e99bbcacd73047559 to your computer and use it in GitHub Desktop.
<?php
// Si no hay búsqueda, mostrar un arreglo vacío y salir
if (empty($_GET["busqueda"])) {
echo "[]";
exit;
}
$bd = include_once "bd.php";
$busqueda = $_GET["busqueda"];
$sentencia = $bd->prepare("select * from mascotas where nombre like ?");
$sentencia->execute(["%$busqueda%"]);
$mascotas = $sentencia->fetchAll(PDO::FETCH_OBJ);
echo json_encode($mascotas);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment