Mysqli选择语句准备语句,带有值插入

时间:2014-02-15 04:22:29

标签: php mysql

我试图使用php预编译语句从数据库中选择用户名和密码。当我从数据库运行它时,它运行SELECT User Name,Password FROM Users WHERE Username ='user'AND Password ='password'LIMIT 1.当浏览器运行它时,它提供了许多参数。

    private function authenticate()
{

    $query = "SELECT Username, Password FROM Users WHERE Username =?
              AND Password =?
              LIMIT 1";

    //prepare query and execute
    if(!$stmt = $this->connection->prepare($query))
    {

        print "Failed to prepare statement";

    }

    else
    {

        $stmt->bind_param('ss', $this->username, $this->password);
        $stmt->execute();

        $stmt->bind_result($username, $password);

        $stmt->store_result();

        $stmt->fetch();


        if($stmt->num_rows > 0) 
        {

            $this->status = 'Logged In';
            $this->setSessions();

        }

        else
        {

            $this->status = 'Not Logged In';

        }

    }    

    $stmt->close();


echo json_encode(array($this->status));

}

0 个答案:

没有答案