If I opened a connection to insert data into a database with
$conn = new mysqli($HOST, $USUARIO, $PASSWORD, $DB);
What is the correct way to close the connection at the end of my script?
If I opened a connection to insert data into a database with
$conn = new mysqli($HOST, $USUARIO, $PASSWORD, $DB);
What is the correct way to close the connection at the end of my script?
The information in the PHP Manual is very poor about closing mysqli connections. It doesn't even indicate how to do it using the object-oriented style. In fact, the connection can be closed in two ways.
A. Object Oriented Style
B. Procedural Style
If you want to have consistent code, without mixing styles, I would recommend using option A. , since when creating the connection you used the object-oriented style:
Mixing styles is considered a bad practice.
It is also important to note that the Manual indicates this in a note:
Use the built-in function