Typcial Enteprise SaaS app connecting to Database

I’m looking for the best practice to connect a web app to a database. In our MVP, we connect like this, but I suspect it’s not ideal:

1. We use a config.php file to store DB details:

define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'blahblahblah');
define('DB_PASSWORD', 'blahblahblah2');
define('DB_NAME', 'blahblahblah');
define("SITEURL","https://blah.blah.com/");

2. We call config.php from other .php pages.

This approach keeps the DB connected unnecessarily, posing security risks. How should we implement DB connectivity using Express.js and Laravel v10 on PHP 8.2?

What is the industry standard, best practice to establish a backend database connections? How can I use jwt for this use case? Or is there a more secure way?