Link to home
Start Free TrialLog in
Avatar of MattMeister
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.
SOLUTION
Avatar of hernst42
hernst42
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Roonaan
Roonaan
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MattMeister
MattMeister

ASKER

Thanks for the comments so far, what i am really using this for is a basis for learning where OOP can be used and the benefits it servers over standard functions etc. I now understand the theory of "object oriented" so i guess what i am looking for is some opinions and tips about good uses and practices with classes.

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...
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
Thanks to all