MattMeister
asked on
Good use of a class?
class conn {
function go($host,$user,$pass,$db) {
$conn = mysql_connect($host,$user, $pass) or die("mySQL connect error");
mysql_select_db($db,$conn) or die ("mySQL DB error");
}
}
$conn = new conn;
$conn->go("localhost","*** **","***** ","*****") ;
What i want to know is, is it worth connecting to a DB this way?
In this case would it make more sense to just directly call the functions mysql_connect and mysql_select_db?
If this is a logical use is there anything i can do to improve its functionality, i was thinking of writing it without the go function so i just had the class and two connect lines but wasn't sure if this would actually serve any benefit.
Thoughts please...
Points will be increased if my knowledge of OOP is expanded throughout this question.
function go($host,$user,$pass,$db) {
$conn = mysql_connect($host,$user,
mysql_select_db($db,$conn)
}
}
$conn = new conn;
$conn->go("localhost","***
What i want to know is, is it worth connecting to a DB this way?
In this case would it make more sense to just directly call the functions mysql_connect and mysql_select_db?
If this is a logical use is there anything i can do to improve its functionality, i was thinking of writing it without the go function so i just had the class and two connect lines but wasn't sure if this would actually serve any benefit.
Thoughts please...
Points will be increased if my knowledge of OOP is expanded throughout this question.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
i forgot to give you the link for the adodb library, so here it is if you want it...
http://adodb.sourceforge.net/
Its a great library, i recommend giving it a look.
http://adodb.sourceforge.net/
Its a great library, i recommend giving it a look.
ASKER
Thanks to all
ASKER
I guess maybe an example is the best way for me to learn so say if i had a class which needed to be fed two variables which needed to be processed by two functions thereafter. What would the bare bones structure look like in a well written class, firsrt creating the object, then defining the variables and then calling the functions...