I know that PHP automatically closes open MySQL connections at the end of the script, and the only viable way to open a persistent connection is to use the appropriate PHP function; many questions and answers were asked. What I would like to know is the advantage - or inconvenient - of maintaining a temporary connection instead of a permanent connection
EDIT:
Permanent connection for each PHP user session.
For example, expressions such as:
session_start();
$connection = new mysqli($host, $user, $pass, $db);
$_SESSION['connection'] = $connection;
can set a reference to the mysqli object, useful for executing multiple queries in site navigation in the same session by the same user. If you intend to use the connection shortly after activating it, would it not be the right choice to leave it open for further requests? Perhaps this approach will create an uncomfortable situation (and possible security risks) when several users will request HTTP pages from a website that supports MySQL connections? I would like to know more. Thank.
source
share