The ideal concept is to make a php script and then create a cron job to run this script every 5min for example and the php will create in a file the statistics you want, after that you can print the file as you like.
See how this concept avoids public interaction with server database?
also i dont recommend mysqli use PDO instead with try/catch so your passwords wont be printed on connection failures