Pergunta

I have a function to calculate which inputs MD5 of the user id and outputs the id,name

public function verifyUser($enc)
{
    //echo $enc;
    $query = $this->db->prepare("SELECT id,name FROM `users` WHERE MD5(`id`) = '$enc'");
    //$query->bindValue(1,$enc);
    $query->execute();
    $data = $query->fetch();
    //var_dump($query);
    return $data;
}

But the above query always results NULL.

eg I have a user with id=2 and MD5(2) is c81e728d9d4c2f636f067f89cc14862c. The query it generates is :

SELECT id,name FROMusersWHERE MD5(id) = 'c81e728d9d4c2f636f067f89cc14862c'

But though the user exits , it results null.

Foi útil?

Solução

Query alone is working as expected. check this SQLFiddle: http://sqlfiddle.com/#!2/e262d/1

however seems to be the following line has some issue. try this corrected one:

$query = $this->db->prepare("SELECT id, name FROM users WHERE MD5(id) = '$enc'");

note: I have removed the wrong quote character present in your code surrounding users and id.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top