We receive both PDOException and warnings. These warnings drive us crazy.
Warning: PDOStatement :: execute (): MySQL server went to /home/Database.php on line 120
Warning: PDOStatement :: execute (): Error reading the result set header in /home/Database.php on line 120
Here is the code that does this - it just simulates a connection going away :
$db = new PDO('mysql:dbname=' . $name . ';host=' . $host, $user, $pass);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
$statement = $db->prepare('SET SESSION wait_timeout = 1');
$statement->execute();
sleep(3);
try {
$statement = $db->prepare('SELECT 1');
$statement->execute();
} catch (PDOException $e) {
echo 'Exception! Err #:' . $e->errorInfo[1] . PHP_EOL;
}
EDIT: The question is, why does this raise a warning and an exception. The above code generates both values, even if we specifically indicate PDO to select exceptions.
The above code does this faster than waiting for our servers by default wait_timeout.
2: , . , PHP , PDO?