I need to bring the data from the Database using an id. The Users class has the following function:
public function getPerfil($id) {
$stmt = $this->mysqli->prepare("SELECT id_usuario,nombre,apellido FROM usuarios WHERE id_usuario = ?");
$stmt->bind_param("i", $id);
$stmt->execute();
$stmt->bind_result($idDB, $nombreDB, $apellidoDB);
while($row = $stmt->fetch()) {
$data[] = $row;
}
return $data;
$stmt->close();
$this->mysqli->close();
}
In the Database I have the column: id, first and last name and I want to show your data by calling them from another file:
session_start();
require_once "clases/Usuarios.php";
$perfil = new Usuarios();
$datos = $perfil->getPerfil(1);
echo $datos->id;
echo $datos->nombre;
echo $datos->apellido;
And I get an error:
Notice: Trying to get property of non-object
Is there any way to show the data of the BD through these queries? I can see them correctly if I show them inside the While of the query, for example: echo $nombreDB;
but I do not want them there. I want to call them from another file to show where I want.