title: How to return integer of COUNT mysql query result in PHP
body: <p>I'm just putting a simple PHP program together that simply counts the number of total rows in my database and returns the result as a JSON object when it recieves a get request from my frontend.</p>
  <p>This should all be super simple but for the life of me I can't figure out how to retrieve the count result in a usable format. All I get from this is &quot;null&quot;</p>
  <p>any ideas?</p>
  <pre><code>$con = mysqli_connect($servername, $username, $password, $dbname);
  if (!$con) {
      die('Could not connect: ' . mysqli_error($con));
  }
  
  $query=&quot;SELECT COUNT(*) FROM database&quot;;
  $result = mysqli_query($con,$query);
  $count = mysqli_fetch_assoc($result);
  echo json_encode($count);
  </code></pre>