I ran into the same issue with a locally hosted Moodle 2.7.8. Started having issues with course restores from publishers and from an earlier instance of Moodle 2.6, also hosted locally. Basically, I would try to restore and after selecting "merge contents into this course" I would get an error message reading "error writing to database." For a few courses I stripped out bigger items (like folders and powerpoint files), and had mixed success restoring elements of the courses this way.
In any case, I had success restoring everything after changing Max_packet_size to 100 MB, as suggested by Ken. For those that encounter this issue in the future, I would start here.
Again, thanks a lot for your contributions, Ken. You're the man.