Since today I passed the variable of my non-static database to the functions of my php project, that needed database access.
I read all about multiple database connections, so I changed my database connection to a static function, so I have in all my functions access to my database connection without passing it as a function´s parameter. So, it is possible to access my database connection (even different databases) by using e.g.: myDatabaseConnection::myFirstdatabase->prepare and so on…
The thing is: What is best practice? Is it good to do that this way. Some of my functions (for example to read some data out of the database) depend on an database connection, but if I remove the database connection variable from the parameters of the function it seems to me that something (a kind of dependency) is missing.
So what is the best practice for that? Do you pass the database connection as a variable to your functions that need database access?
Thank you very much.
I understand the thing with the connection.
But what about the other functions in my project; like e.g. a function to read all member names out of a database?
Do you pass a database connection variable to that function or do you access the connection to the database inside of that function using my “global” static database conncection. I know, that it is not global, but my static database connection can be accessed from everywhere…
CLASSdatabase.php