我有一个更早的帖子here
但这些答案都不起作用。这是我的整个班级代码:

<?php
session_start();
class Mysql {
    private $conn;

    function __construct() {
        $this->conn =  new PDO('mysql:host=***;dbname=***;charset=UTF-8','***','***') or
                      die('There was a problem connecting to the database.');
    }

    function verify_Username_and_Pass($un, $pwd) {
        $query = "SELECT Username
                FROM Conference
                WHERE Username = :un AND Password = :pwd";

        $stmt = $this->conn->prepare($query);

        $stmt->bindParam(':un', $un);
        $stmt->bindParam(':pwd', $pwd);
        $stmt->execute();
        if ($stmt->rowCount() > 0) {
            // User exist
            $stmt->bindColumn('First Name', $firstName);
            $_SESSION["FirstName"] = $firstName;
            die($_SESSION["FirstName"]);
            return true;
            $stmt->close();
        }
        else {
            // User doesn't exist
            //die("failure");
            return false;
            $stmt->close();
        }
    }
}
?>

我试过取,试过bind_result,等等,但没有一个在die语句上打印正确的值。现在,当我在会话中存储用户名并尝试打印时,这个方法就起作用了。密码怎么了?

最佳答案

你没有调用代码片段中的代码。呼叫程序是什么?
您没有只检索Conference.First Name所以应该会收到警告,除非您没有显示错误。你可能想要
Conference.Username

"SELECT * FROM Conference...."
可能是"SELECT FirstName From Conference WHERE Username = :un AND Password = :pwd";
Conference.FirstName对调试不是很有用。尝试die();

关于php - PHP从数据库检索列数据,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12696302/

10-12 04:53