Only store one result from PDO (SQL) in a variable
07:20 17 Mar 2026

I always use this method, for example, to get just a single value. It’s obviously not the most elegant solution, but it works.

Is there a shorter way to do this without a fake loop? And the result has to be stored in a variable somehow...

foreach ($pdo->query("SELECT COUNT(*) FROM import WHERE tn_nr='12345'") as $tn){}
echo $tn[0];
php sql mysql pdo