Jump to content

How should I be dealing with MySQL connection...


cgm225

Recommended Posts

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!

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.