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.