php - Issue with counting rows using MySQLi -


this question has answer here:

when trying execute mysqli statement that's supposed count rows. don't error when query when try , echo result, breaks html lines below echo.

here code:

$db = dodb(); $sql = "select count(*) `keys`"; $stmt = $db->query($sql)->fetchcolumn(); 

dodb() function:

function dodb() {  $dbhost = 'localhost';  $dbname = '';  $dbuser = '';  $dbpass = '';   $db = new mysqli($dbhost, $dbuser, $dbpass, $dbname);  return $db; } 

after long discussion can count that:

$result = $db->query("select count(*) `keys`"); $row = $result->fetch_row(); echo $row[0]; 

note credit goes @deceze.


Comments