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

Asked

Viewed 90 times

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 making a query to recover only the lines that have status 1, my query SQL 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 him to return all emails that meet this status equal to 1, not only the first occurrence, nor the number of lines affected by query, so far I could not, because or just return me the first occurrence using $stmt->fetch(); or else the number of affected lines using $stmt->rowCount();

1 answer

6


Use the method fetchAll:

$contents = $stmt->fetchAll(PDO::FETCH_ASSOC);
  • Very simple rs and it worked... Thank you very much ;)

Browser other questions tagged

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