How to make a single point of entry for connect to database?

Hello! I decided then to sit down and throw together a small personal account (admin in other words). Nothing super fancy, and global. In the database there is a table users and there are regular columns for the data.
So. I decided then to organize the registration (Name,password,email). Created a file index.php with the usual form that on submit needs to throw the data into the table.
I used these things done using the require_once the connection file connect where was the settings for the database.
And this connect the file I was dumped wherever it was necessary to appeal to the base. I thought it was absurd and uncomfortable. Googled, found something like a "single entry point" or "to make connection to private class".
And here the question!!! What does this mean? Does anyone have manuals or modern examples of such connection settings?
Just wanted at least one little project to do on a human.
June 10th 19 at 15:28
3 answers
June 10th 19 at 15:30
Option 1. In haste and effectively. To not go into deep details, to solve the problem, you can use the framework. For Instance Slim. It is lightweight and quite easy to learn and it just implemented out of the box the same single point of entry. In their documentation everything is described in detail how to build an application that connects as a base, how does routing how to connect a template engine such as twig and much more. In the Russian language.
Option 2. Difficult, but you can get more experience. Writing classes, including a class for connecting to database. Put them in a folder. The single point of entry will be traditionally file index.php in which you want to use spl_autoload. To apply for the different URLs of your app, not directly to the php files will need routing. On this issue again, there is a lot of information in the network.
June 10th 19 at 15:32
And here the question!!! What does this mean?


Exactly what is written. To create a class that will be responsible for the connection to the database =)
June 10th 19 at 15:34
I used these things done using the require_once the connection file connect where was the settings for the database.

Google composer autoloader
"to make connection to private class"

Google php singleton db
on the forum one dug up:
1) Declare a static class for work with DB.
2) Write methods, which are needed. Take into account that the DB connection was done only during the request and not in advance. There's also a stored connection. They also return the results.
3) Catches this class's entry point. Only once.

If the first two points more clear how to do, 3rd I do not know.
How is the entry point? - reyes11 commented on June 10th 19 at 15:37
you need to Google the architecture similar to MVC. There is responsible for this the module routing - Sammie_Bart commented on June 10th 19 at 15:40

Find more questions by tags MySQLPHP