refactor
use prepared statements for most quesries. Be sure to close them
Re-use prepared when we can
comment use
Simplify.
no idea why this was a string
Some nits detected by PhpStorm
require smarty3