stmt prepare nothing appears to me

0

I have this code to print the data on the page that comes from the database:

<?php

    session_start();
    include "conection.php";

    $id_login = $_SESSION["id_login"];

    $stmt =$db->prepare("select login.username, login.nome, login.id_login from login where login.id_login=?");

    $stmt->bind_param('i',$id_login);
    $stmt->execute();
    $stmt->bind_result($username,$nome,$id_login);
    $stmt->fetch();
    $stmt->close();
?>

I've already tested the query and that's fine. Also returns the session variable $id_login . But the page goes blank and I do not know what the error is. Thank you.

    
asked by anonymous 30.01.2016 / 15:47

1 answer

0

The code does not look wrong, but there is nothing that makes print result on it. Try this:

<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);

session_start();

$db= new mysqli("host", "user", "password", "database");

if (mysqli_connect_errno()) {
    echo "Error: ".mysqli_connect_error();
    exit();
}


if ($stmt = $db->prepare("SELECT login.username, login.nome, login.id_login FROM login WHERE login.id_login = ?")) {

    $stmt->bind_param('i', $id_login);
    $id_login = $_SESSION["id_login"];

    $stmt->execute();
    $stmt->bind_result($username, $nome, $id_login); // deve ter o mesmo número de variáveis e colunas na tabela

    while ($stmt->fetch()) {
        echo $username."|".$nome."|".$id_login."<br/>";
    }
    $stmt->close();
}

$db->close();

?>
    
30.01.2016 / 17:46