`dbal $db` should be `phpbb_db_driver $db` or else you'll get a fatal error.