How should I be dealing with MySQL connection...
Posted: Thu Apr 24, 2008 8:01 am
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!
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!