如何从PDO Db获取查询并将其与电子邮件ID匹配?

时间:2014-12-21 12:10:13

标签: database pdo

我已尝试过所有我已阅读的内容以及更多内容,但无论我如何配置此查询,我都无法从WHERE activation_key =?获得任何结果?

$id = $_GET['id']; // This is the $key id in the email - Not the user's ID and it needs to match the query from the database?

$stmt = $database -> prepare("SELECT activation_key FROM " . USERS_TABLE . " WHERE activation_key =?");
$stmt -> execute(array(':activation_key' => $activation_key,':id' => $id ));
$row = $stmt->fetch(PDO::FETCH_ASSOC);

$key = $row['activation_key'];

// This echo is only for testing?
echo 'Key = '.$key.' >>  ID = '.$id.'';

if($key == $id){ Do Stuff

但无论配置是什么,密钥总是空的? :(

尝试将其包装为代码并不起作用。

1 个答案:

答案 0 :(得分:0)

感谢您的回答 - 我将对其进行测试 - 但此刻对我有用,如果您的建议更好,我会回来的,因为它看起来更容易......

但我确实找到了解决方案吗?

http://wiki.hashphp.org/PDO_Tutorial_for_MySQL_Developers

错误!:)

$id = $_GET['id']; // This is the $key id in the email - Not the user's ID and it needs to match the activation_key from the Db

$stmt = $database -> prepare("SELECT activation_key FROM " . USERS_TABLE . " WHERE activation_key =?"); 
$stmt -> execute(array(':activation_key' => $activation_key,':id' => $id ));
$row = $stmt->fetch(PDO::FETCH_ASSOC);

$key = $row['activation_key'];

// This echo is only for testing?
echo 'Key = '.$key.' >>  ID = '.$id.'';

        if($key == $id){

但对于“其他”人的利益,有一天可能会遇到同样的问题>也许这会有所帮助吗?

从右

$stmt = $database->query("SELECT username, activation_key FROM " . USERS_TABLE . "");

while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {


$name = $row['username'];
$key = $row['activation_key'];
}

// This echo is only for testing?
echo 'Name = '.$name.' >> Key = '.$key.' >>  ID = '.$id.'';

// RETURNS: Name = slopalong >> Key = 123456 >> ID = hTPAobi0 

        if($key == $id){ Do Stuff

并且可能创建另一个GET并在EMAIL网址中添加两个参数以使用户与密钥匹配。