-1

When trying to execute my MYSQLi statement that's supposed to count rows. I don't get an error when I do a query but when I try and echo the result, it just breaks the html lines below the echo.

Here is my code:

$db = doDB();
$sql = "SELECT COUNT(*) From `Keys`";
$stmt = $db->query($sql)->fetchColumn();

doDB() Function:

function doDB() {
 $dbHost = 'localhost';
 $dbName = '';
 $dbUser = '';
 $dbPass = '';

 $db = new mysqli($dbHost, $dbUser, $dbPass, $dbName);
 return $db;
}
stat.us
  • 113
  • 1
  • 2
  • 8

1 Answers1

1

After long discussion you can get count like that:

$result = $db->query("SELECT COUNT(*) From `Keys`");
$row = $result->fetch_row();
echo $row[0];

Note that this credit goes to @deceze.

devpro
  • 16,184
  • 3
  • 27
  • 38