When creating your own library for working with a database, the constructor (the __construct method)
is the part of the code that does the most important work behind the scenes. Its main task is to execute
automatically as soon as you create a new object of your class. Instead of writing connection code in each file
separately, the constructor does it for you – it prepares the DSN string, checks the credentials, and establishes a
secure PDO connection, which is then ready to be used throughout the entire application.
By doing this, we ensure that we do not have to write connection code in every single file. We set up the class once, and then we just use it. Any potential connection errors are caught inside the class, which keeps our main code clean.
__construct.