cgm225 Posted April 24, 2008 Share Posted April 24, 2008 I am creating an authentication class in which I check a provided username and password against a database table of usernames and passwords. My question is, how should I be providing the MySQL connection information to the class for this check? Should I pass all the parameters (i.e. the MySQL login info (user, pass, database) table and table fields)) and then establish a connection and query within the class? Or should I open up a connection outside the class and set that connection to a variable and then pass that to the class? Should I pass the query statement? I just want to keep things flexible and generic, and wasn't sure of the best way to do this. What would you recommend? Do you have any simple example code you could provide? Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/102713-how-should-i-be-dealing-with-mysql-connection/ Share on other sites More sharing options...
DarkWater Posted April 24, 2008 Share Posted April 24, 2008 Pass the connection. Or you could make a connect method inside of the class. But here's the big question: Are you going to need the connection for anything OTHER than authenticating on that page? If you are, then pass the connection, otherwise make a static method inside the class, so you could call Authenticate::connect() when you need it in the script. Link to comment https://forums.phpfreaks.com/topic/102713-how-should-i-be-dealing-with-mysql-connection/#findComment-525955 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.