I am trying to convert my site to PDO and keep getting this error:

Warning: PDOStatement::execute(): MySQL server has gone away in Code (markup):


Warning: PDO::query(): Error reading result set's header in Code (markup):


Fatal error: Call to a member function fetchAll() on a non-object in Code (markup):

Any ideas?

I've tried increasing max_allowed_packet. Strange thing is it doesn't give the errors every time. Only occasionally. Not sure what the deal is.