Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created September 19, 2019 18:29
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/1a4479cbba153608d5b6b91f2044a206 to your computer and use it in GitHub Desktop.
Save parzibyte/1a4479cbba153608d5b6b91f2044a206 to your computer and use it in GitHub Desktop.
<?php
public function read($id_de_sesion)
{
$sentencia = $this->base_de_datos->prepare("SELECT datos FROM sesiones WHERE id = ?;");
$sentencia->execute([$id_de_sesion]);
# Recuperar como objeto (con PDO::FETCH_OBJ), para acceder a $fila->datos
$fila = $sentencia->fetch(PDO::FETCH_OBJ);
# Si no existen datos con ese id, fetch devuelve FALSE
if ($fila === false) {
return ""; # Cadena vacía
} else {
return $fila->datos;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment