Return value from select

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's password value?

    
asked by anonymous 22.06.2015 / 20:03

1 answer

1

To retrieve the values, you get by fetch(PDO::FETCH_ASSOC) , like this:

$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;
    }
}
    
22.06.2015 / 20:20