Francisc
Francisc

Reputation: 80385

Get the single returned value with PDO

For this query: $sql='select col from table where other_col=?';

I am currently getting the returned data like so: $data=$statement->fetch()['col'];

That doesn't look very good to me. Is there a better way of doing that or is that fine as it is?

Upvotes: 5

Views: 5860

Answers (1)

caRameL
caRameL

Reputation: 633

You can try :

$data=$statement->fetchColumn(0);

Upvotes: 13

Related Questions