You're outputting to the screen. Check for whitespace characters before the php code
Have a look at this PDO class. https://www.culttt.com/2012/10/01/roll-your-own-pdo-php-class/ I started with MySQLi and within a few hours switched to PDO. People I work with like MySQLi and they can't see the benefit of PDO. Drives me nuts ?