Did you write web_req_init.php yourself or is it a library provided by a vendor? I can't really tell what you are trying to achieve.
The code you show looks very "old school" PHP and will likely require some changes to work in an MVC application like Flarum.
If the code needs to run once for every request, a middleware class is a good place to put it https://docs.flarum.org/extend/middleware
If the code needs to be called via an AJAX request, an API controller is probably the right solution https://docs.flarum.org/extend/routes#api-controllers
To load external libraries, the recommendation is to use Composer psr namespace definitions. If that's not possible, you can add your file to the list of autoload files in the composer.json of your extension.
To obtain an instance of the database query builder, you can use inversion of control (IoC) by adding Illuminate\Database\Connection as a constructor parameter to your middleware or controller. The container will automatically provide an instance when the class is created. Or you can use resolve(Illuminate\Database\Connection::class) (but using IoC is the recommended method)