Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Seth Warner
Seth Warner
5,348 Points

If I have a php database connection established in a file on a project name database.php

If I have a php database connection established in a file on a project name database.php and I am using require_once('database.php'); on whatever other files I want to establish that connection with, Can I set up multiple database connections in that database.php file and assign each one to its own PDO and use them through the same require_once connection, allowing me to use whatever database I need throughout a file by there distinct PDO name, allowing me to pull data from many other databases perhaps combing them on a php file?

sure thing you can, you just have to build a class that contains the parammetters for the PDO connection in nothing but variables and within the __construct function assign thos variables as parammeters of your database class, then when you include the database.php file in another file you also add the instance of that class and put the PDO parammetters within the parenthesis and that'll do it.