Get a single return value using PDO

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

I am currently receiving the returned data as follows: $data=$statement->fetch()['col'];

This is not very good for me. Is there a better way to do this or is it perfect as it is?

+5
source share
1 answer

You can try:

$data=$statement->fetchColumn(0);
+11
source

All Articles