Question regarding persistent connections

I got 2 questions regarding them, assuming I got a file called config.php and it is being included in all pages by php require.
In config php I got these 2 lines:

$mysqli = new MySQLi('p:127.0.0.1', 'x', 'y', 'z');
$mysqli->set_charset('utf8');
  1. Is it ok that its being called on every page? (does it knows automatically to reuse old connections rather than creating a new one?)
  2. I don’t need to call close() right?
  1. Yes, it is. Without such a call you won’t have a $mysql variable, which gets quite inconvenient when it comes to running a query.
  2. Right. However, it won’t do any harm if you call it

Connecting to MySQL isn’t configuration. The authentication info to connect to MySQL such as; username, password, db, and port is but establishing the connection falls under bootstrapping NOT configuration. Most modern applications even defer connecting until the connection is needed. So putting that in a file called config.php is kind of a sloppy, unorganized way to go about it.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.