Return value from select

Asked

Viewed 452 times

0

$sql = "SELECT username, mail, password FROM users WHERE username = :user_name OR mail = :user_name;";

$query = $this->db->prepare($sql);
$query->bindParam(':user_name', $user_name);
$query->bindParam(':user_password', $user_password);

$query->execute();

How do I return the user password value?

  • If you are explicitly storing your users' password in the database, you’re making a fool of yourself.

  • I’m hashing '-' http://prntscr.com/7k1d7l

  • Read the link I sent - MD5 or SHA1 (or SHA-whatever) are not enough.

1 answer

1


To recover the valroes, you take the hair fetch(PDO::FETCH_ASSOC), thus:

$stmt = $pdo->prepare("SELECT username, mail, password FROM users WHERE username = :user_name OR mail = :user_name;");

$stmt->bindParam(':user_name', $user_name);
$stmt->bindParam(':user_password', $user_password);

$usuarios = array();
if ($stmt->execute()) {
    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
        // seu objeto $row que possui os username, mail, password

        // para adicionar o resultado num array
        $usuarios[] = $row;
    }
}
  • And if I want to recover only the user password value ?

  • is by the $Row inside the while, $row["password"]

  • I made the code without while, and returned the right value. Is there any problem?

  • No, it’s just the iteration of the result :)

  • Is that in its context will not really return + 1 result, so no problem

Browser other questions tagged

You are not signed in. Login or sign up in order to post.