I have began a little practice project after I have finished the book Php From Novice to Ninja. Like in the book, I have set up the database connection and a functions file, which you can see here:
With this setup, I have to include the db.php file inside every function to be able to use $pdo. I am wondering, is there a way to set up the database connection code so I don’t have to include the db.php in every function?
Best practice would be to put it into a class and then autoload that either with spl_autoload_register or to use something like https://getcomposer.org with PSR-0/PSR-4 autoloading.