l0ve2hat3 Posted February 23, 2009 Share Posted February 23, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/146543-classes/ Share on other sites More sharing options...
Maq Posted February 23, 2009 Share Posted February 23, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/146543-classes/#findComment-769360 Share on other sites More sharing options...
l0ve2hat3 Posted February 23, 2009 Author Share Posted February 23, 2009 i was just making using a basic example... i am writing a class to tie a mssql based POS system to the web so customers can place orders check inventory and prices... Quote Link to comment https://forums.phpfreaks.com/topic/146543-classes/#findComment-769362 Share on other sites More sharing options...
rhodesa Posted February 23, 2009 Share Posted February 23, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/146543-classes/#findComment-769363 Share on other sites More sharing options...
l0ve2hat3 Posted February 23, 2009 Author Share Posted February 23, 2009 ok i got it... i am not going to have it echo anything.. i was just using that function as an example without going into boring details... Quote Link to comment https://forums.phpfreaks.com/topic/146543-classes/#findComment-769364 Share on other sites More sharing options...
premiso Posted February 23, 2009 Share Posted February 23, 2009 <?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. Quote Link to comment https://forums.phpfreaks.com/topic/146543-classes/#findComment-769366 Share on other sites More sharing options...
rhodesa Posted February 23, 2009 Share Posted February 23, 2009 if this is your first time with OOP, i would give this a read: http://devzone.zend.com/node/view/id/638 Quote Link to comment https://forums.phpfreaks.com/topic/146543-classes/#findComment-769367 Share on other sites More sharing options...
Maq Posted February 23, 2009 Share Posted February 23, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/146543-classes/#findComment-769368 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.