[ticket/12765] Use db_tools instead of generating queries at moment

https://tracker.phpbb.com/browse/PHPBB3-12765

PHPBB3-12765