bindParam与md5()列PDO PHP

时间:2015-01-12 14:29:12

标签: php mysql pdo md5

我尝试比较数据库内部的用户密码和登录表单中的内容,但是当我这样做时:

$stmt = $dbh->prepare('SELECT * FROM users WHERE (username = :username, password = :password)');
$stmt->bindParam(':username', $_POST['username']);
$stmt->bindParam(':password', md5($_POST['password']));
$stmt->execute();
$stmt->fetch(); // return false

我做错了什么?

3 个答案:

答案 0 :(得分:2)

您应该像这样编写查询:

SELECT * FROM users WHERE (username = :username AND password = :password)

答案 1 :(得分:2)

你的查询错了。 试试这个:

$stmt = $dbh->prepare('SELECT * FROM users WHERE username = :username AND password = :password');

答案 2 :(得分:1)

使您的查询正确。使用以下代码

$stmt = $dbh->prepare('SELECT * FROM users WHERE username = :username AND password = :password');
$stmt->bindParam(':username', $_POST['username']);
$stmt->bindParam(':password', md5($_POST['password']));
$stmt->execute();
$stmt->fetch(); // return false

希望这有助于你