Select语句无法正常工作

时间:2013-09-11 14:56:29

标签: php mysql sql mysqli

从数据库中选择后,当实际为1时,我一直保持0

代码:

    $username = $_SESSION['username'];
    echo $username;
    $sql = "SELECT activated FROM members WHERE username = ?";
        $stmt = $conn->prepare($sql);
        $stmt->bind_param('s', $username);
        $stmt->execute();
        $stmt->bind_result($emailactivated);
        $stmt -> close();
    echo $emailactivated;

Echo说0 ..它应该是1,注意:$ username不是空的

1 个答案:

答案 0 :(得分:0)

你错过了$stmt->fetch()

http://php.net/manual/en/mysqli-stmt.fetch.php

    $stmt = $conn->prepare($sql);
    $stmt->bind_param('s', $username);
    $stmt->execute();
    $stmt->bind_result($emailactivated);
    $stmt->fetch();  //right here
    $stmt -> close();