Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created September 19, 2019 18:29
Embed
What would you like to do?
<?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