just for the records, put it inside the while loop.
new mysqli() or die() wont’t work. in case you have no connection you will still get an mysqli object. you explicitly need to test with myqli->connect_error
The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
André Behrens, NY Times Software Developer