With only one column selected, the make fetch method does not return a row. In most cases, it still returns its associative default selection array.
To access it as a column
you need to add a column alias AS$stmt = $dbh->prepare("SELECT count(*) AS cnt FROM Users");
$stmt->execute();
$result = $stmt -> fetch();
echo $result['cnt'];
source
share