-
-
Save parzibyte/3cfc069e9a1036e2a610aa91c7bf8454 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 | |
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