可捕获的致命错误:类PDOStatement的对象无法在第10行转换为字符串

时间:2017-07-28 13:48:35

标签: php pdo

我在注册新帐户时仍然收到此错误

  

捕获致命错误:PDOStatement类的对象无法在第10行转换为字符串

class User {
    var $name = "";
    var $email = "";
    var $user_id;

    function __construct($user_id) {
        global $pdo;
        $this->user_id = $user_id;
        $user_info = $pdo->prepare("SELECT * FROM users WHERE user_id = :id");
        $user_info->execute(array(":id" => $user_id));
        $result = $user_info->fetch(PDO::FETCH_ASSOC);
        $this->email = $result["email"];
        $this->name = $result["name"];
    }

    public static function createUser($email,$password,$name) {
        global $pdo;
        $check = $pdo->prepare("SELECT user_id FROM users WHERE email = ?");
        $check->execute(array($email));
        $stmt = $check->fetch();
        if(isset($stmt["user_id"])) {
            return false;
        }

        $password_hash = hash('sha256', $password);

        $user_id = $pdo->prepare("INSERT INTO users
            (email, password, name)
            VALUES (?,?,?)");
        $user_id->execute(array(
            $email, $password_hash, $name));

        return new User($user_id);

    }

}

任何人都可以帮助我吗?

0 个答案:

没有答案