I have two files:
config.php:
$con = mysqli_connect("$dbhost","$dbuser","$dbpass","$dbname");
ads.php (config.php require_once):
$query1 = mysqli_query($con,"SELECT * From XXXX where id = 'XXXX'");
$query2 = mysqli_query($con,"SELECT * FROM XXXX2 WHERE id = 'XXXX2'");
I have more than 40 different queries mysqli_query() using $con. Please keep in mind that all my logic is procedural style, not object oriented.
My two questions are:
am I connecting to the DB using a different connection on every query? Or just once when the first one is executed? Is there a better way to do this?
I understand that it is not mandatory to close a mysql connection since it closes itself, however since we have millions of consults sometimes a few can hang and stay for more than 10 seconds after the user left the PHP file. If I wanted to close a connection, should I put mysqli_close($con) at the end of the file (after the 40 consults) or at the end of each consult (40 times)?
Any help would be appreciated. Thanks