I have a rather large site, and each page is built from several included files, my site is 100% in a procedural format, and I'm trying to learn how to use classes and a more OOP approach in PHP.
Currently my site has a header file that is included in each page, a mysql connection is created in this header and the page lasts, so if I need to run 10 different requests from different files, they all start without the need to create a new connection, so the connection performed only once.
Now, when I try to convert to an OO path, I start writing a mysql class to connect and run queries, so I think about using __construct functions to connect to mysql, I'm just curious how this will work, every time the called class will called, it will make or try to establish a connection to mysql instead of once.
Perhaps I do not understand this clearly. Should I just initiate this class in the header 1 time, and then I don’t have to worry anymore?
source
share