Martin AJ
Martin AJ

Reputation: 6697

How to fetch row in PDO?

Here is my code:

$qs_num = $this->dbh->query("SELECT COUNT(amount), COUNT(*) FROM qanda WHERE type = 0");
print_r($qs_num); die;

And here is the result:

//=> PDOStatement Object ( [queryString] => SELECT COUNT(amount), COUNT(*) FROM qanda WHERE type = 0 )

How can I get the result of query above? That query should return 1 row contains tow columns.

Upvotes: 0

Views: 699

Answers (1)

datagutten
datagutten

Reputation: 163

You need to call the fetch method of the PDOStatement object like this:

$row = $qs_num->fetch(PDO::FETCH_ASSOC)

http://php.net/manual/en/pdostatement.fetch.php

Upvotes: 1

Related Questions