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; 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -