If inserting 'too much data' fails due to the max_allowed_packet
setting of the database server, the following warning is raised:
SQLSTATE[08S01]: Communication link failure: 1153 Got a packet bigger than
'max_allowed_packet' bytes
If this warning is catched as exception (due to the set error handler), the database connection is (probably) lost but the application doesn't know about this (failing inserts can have several causes). The next query in line, which can be as simple as:
SELECT 1 FROM DUAL
Will then fail with the error this SO-question started:
Error while sending QUERY packet. PID=18486
Simple test script to reproduce my explanation, try it with and without the error handler to see the difference in impact:
set_error_handler(function($errno, $errstr, $errfile, $errline, array $errcontext) {
if (0 === error_reporting()) {
return false;
}
throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
});
try
{
var_dump($oDb->query('SELECT 1 FROM DUAL'));
$oStatement = $oDb->prepare('INSERT INTO `test` (`id`, `message`) VALUES (NULL, :message);');
$oStatement->bindParam(':message', $largetext, PDO::PARAM_STR);
var_dump($oStatement->execute());
}
catch(Exception $e)
{
$e->getMessage();
}
var_dump($oDb->query('SELECT 2 FROM DUAL'));