mysql - echo PDO query as string in PHP -
basically trying return total number of columns correspond given criteria:
$exec = $link->query("select count(*) `requests` language='php'"); $result = $exec->fetch(pdo::fetch_assoc); echo $result[0];
however, above not return sql query correct since returns value when executed in phpmyadmin.
since explicitly used flag pdo::fetch_assoc
, need point on associative index returns. i'd suggest put alias on count()
select count(*) total `requests` language='php'
then access after fetching:
echo $result['total'];
another way use ->fetchcolumn()
:
$count = $exec->fetchcolumn(); echo $count;