anchor.diff:  	if(!async)
   		start_time = REALTIMEOFDAY
   	Close()
  -	query = connection.BeginQuery(sql)
  -	if(!async)
  -		timed_out = !query.WaitForCompletion()
  -	else
  -		in_progress = TRUE
  -		UNTIL(query.IsComplete())
  -		in_progress = FALSE
  +	timed_out = run_query(async)
  +	if(query.GetErrorCode() == 2006) //2006 is the return code for "MySQL server has gone away" time-out error, meaning the connection has been lost to the server (if it's still alive)
  +		log_sql("Executing query encountered returned a lost database connection (2006).")
  +		SSdbcore.Disconnect()
  +		if(SSdbcore.Connect()) //connection was restablished, reattempt the query
  +			log_sql("Connection restablished")
  +			timed_out = run_query(async)
  +		else
  +			log_sql("Executing query failed to restablish database connection.")
   	skip_next_is_complete = TRUE
   	var/error = QDELETED(query) ? "Query object deleted!" : query.GetError()
   	last_error = error
  
positive.code: 		log_query_debug("Query used: [sql]")
  		slow_query_check()
  
  /datum/DBQuery/proc/slow_query_check()
  	message_admins("HEY! A database query timed out. Did the server just hang? <a href='?_src_=holder;[HrefToken()];slowquery=yes'>\[YES\]</a>|<a href='?_src_=holder;[HrefToken()];slowquery=no'>\[NO\]</a>")
  
  
negative.code: 	if(IsConnected())
  		return TRUE
  
  	if(failed_connection_timeout <= world.time) //it's been more than 5 seconds since we failed to connect, reset the counter
  		failed_connections = 0
  
  	if(failed_connections > FAILED_DB_CONNECTION_CUTOFF)	//If it failed to establish a connection more than 5 times in a row, don't bother attempting to connect for 5 seconds.
  		failed_connection_timeout = world.time + 50
  		return FALSE
  
  	if(!CONFIG_GET(flag/sql_enabled))
  