Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created February 12, 2019 18:22
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/3cfc069e9a1036e2a610aa91c7bf8454 to your computer and use it in GitHub Desktop.
Save parzibyte/3cfc069e9a1036e2a610aa91c7bf8454 to your computer and use it in GitHub Desktop.
<?php
include_once "base_de_datos.php";
# Recuerda que nombre puede venir de cualquier lugar
$nombre = "Parzibyte";
# Seleccionar el id para que sea ligero, pues no necesitamos obtener los datos, solamente
# queremos saber si existe
$sentencia = $base_de_datos->prepare("SELECT id FROM personas WHERE nombre = ? LIMIT 1;");
$sentencia->execute([$nombre]);
# Ver cuántas filas devuelve
$numeroDeFilas = $sentencia->rowCount();
# Si son 0 o menos, significa que no existe
if ($numeroDeFilas <= 0) {
echo "El usuario con nombre $nombre NO existe";
} else {
echo "El usuario con nombre $nombre SÍ existe";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment