Doubt, query does not work exactly as I want ... PHP

2

I have a table in the database called emails , with the following fields:

id
subject
body
e status (0, para não enviado, ou 1, para enviado).

I was doing a query to retrieve only the rows that have status 1, my SQL query was:

"SELECT * FROM emails WHERE status = '1'"

The problem is ... Doing through parameterized query,

$status = "1";

$stmt = $db->prepare("SELECT * FROM emails WHERE status = :status");
$stmt->bindParam(":status", $status, PDO::PARAM_STR);
$stmt->execute();

In the end I want it to return all emails that have this status equal to 1, not just the first occurrence, nor the number of rows affected by query , so far I have not been able to, because or only returns the first occurrence using $stmt->fetch(); or else the number of affected rows using $stmt->rowCount();

    
asked by anonymous 21.07.2014 / 02:14

1 answer

6

Use the fetchAll method:

$contents = $stmt->fetchAll(PDO::FETCH_ASSOC);
    
21.07.2014 / 02:17