I am attempting to make a php + pdo website that has persistent connections. Of course, the connections are closed every 8 hours of inactivity so I am attempting to create a php file that reopens the connection if it is closed
Here is my code:
try{
$db = new PDO("mysql:host=$database_ip;dbname=$database_name", $database_username, $database_password, array(PDO::ATTR_PERSISTENT => true));
}catch(Exception $x){
try{
$db = new PDO("mysql:host=$database_ip;dbname=$database_name", $database_username, $database_password);
}catch(Exception $x){
echo 'Failed database error';
}
}
This says that "PDO::__construct() will always throw a PDOException if the connection fails regardless of which PDO::ATTR_ERRMODE is currently set. Uncaught Exceptions are fatal."
The problem is that even though the exception is caught it is still fatal :/
Here's the error:
Warning: PDO::__construct(): MySQL server has gone away in /path/to/website/mysql.inc.php on line 3