Page 1 of 1

How should I be dealing with MySQL connection...

Posted: Thu Apr 24, 2008 8:01 am
by kilbad
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!

Re: How should I be dealing with MySQL connection...

Posted: Thu Apr 24, 2008 8:10 am
by onion2k
I prefer to open the connection outside of the class and then pass it in by reference. This is because I use ADODB Lite and like to have the connection debugging stuff like timings work even when the connection is reused between several objects.

Re: How should I be dealing with MySQL connection...

Posted: Thu Apr 24, 2008 9:55 am
by pickle
I have my DB class create the connection itself. My Authentication class then calls a singleton function to import the connection.