Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.