Jump to content

classes


l0ve2hat3

Recommended Posts

if i were to write a class to connect to a database and lets say echo something....

 

would i make class to connect and a class to echo

 

or

 

would i make 1 class and put both functions under the class?

 

Why in the world would you make a class to echo?  Could you explain exactly what you're trying to accomplish?

 

You would most likely put both in 1 class but again, you need to explain what you're trying to do.

Link to comment
https://forums.phpfreaks.com/topic/146543-classes/#findComment-769360
Share on other sites

first, i wouldn't have your class echo anything. leave that to the script using the class

 

as far as 1, 2, or more classes, that will depend on how complex you want to make this. you could easily do this all in one class, but you may want separate classes for each "type" of object you will have. off the top of my head, i can think of the following classes:

POS -> This would be the main class that handles top level stuff

POSItem -> Inventory Item

POSOrder -> Sale/Order

Link to comment
https://forums.phpfreaks.com/topic/146543-classes/#findComment-769363
Share on other sites

<?php
class msSql {
    private $con;
   
    public function __construct($host, $user, $pass, $db) {
             $con = mssql_connect($host, $user, $pass); 

             mssql_select_db($db, $con);
    }

    public function query($sql) {
          return mssql_query($sql);
   }
}
?>

 

Something like that is a rough example, I am not sure how MSSQL works, so the functions may not be correct. But yea.

 

 

Link to comment
https://forums.phpfreaks.com/topic/146543-classes/#findComment-769366
Share on other sites

I would recommend drawing up a classes diagram of what you think is right and what you're trying to do.  Check out some existing designs that are similar to yours so you can base your off it.

 

If you have questions you can post it for feedback.  It's hard to say what exactly you should do when we don't know how complex this is going to be.

 

Good luck!

Link to comment
https://forums.phpfreaks.com/topic/146543-classes/#findComment-769368
Share on other sites

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.