WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've added $this->query("set session wait_timeout=600"); into wp-includes/wp-db.php file because of "MySQL has gone away" errors in every query and I need to find some way to do the changes in file persistent (I suppose update of WordPress rewrites wp-db.php file).

Any ideas?


share|improve this question

Not a good idea to modify core WP files. Figure out the issue with the MySQL server dying: it's going to be lack of good server configuration, a (very) bad quality host or a theme that is very database query-intensive.

Fixing the underlying cause of the database server errors is the best thing to do in the long run; hacking core files is a bad, temporary fix.

share|improve this answer

Of course, WordPress overwrites its own Core file on update. That is why you don't hack them.

I am not exactly sure where you have inserted that code, but I suspect it may be in several places.

My first though is "talk to your host" or "adjust the global MySQL settings" (if you can). And of course, fix your site. There is almost certainly some poor quality code.

If you really must run an altered database object copy the whole wp-db.php file to wp-content/db.php and make your edits there. WordPress will load the altered file instead. It is called a "drop-in". This is a last resort. It really shouldn't be necessary on a decent host with decent code, and using a "drop-in" for this kind of hack is probably an abuse of the concept.

share|improve this answer
"drop-in" files are very interesting; I didn't know that. – markratledge Jan 22 '14 at 15:30

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.