TheFilmGod Posted January 9, 2010 Share Posted January 9, 2010 Hello, For quite some time, I have been using functions to validate form input and access the databse. I have recently started using OOP, which is far faster and better when it comes to programming (performance aside). My question: How do I access the database within a specific validation class. Example: class validateLogin { // Class properties public $value; public $msg; public $valid = 0; // Access database and do some stuff to check } I added in the "public" to show how I would get values into the class from the public variable scope. Would I do the same for the database? A problem would arise because I use a database class to access mysql. Can I have a class within another class? I could use a normal function and basic coding, but I like php classes. Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/187889-access-database-inside-of-a-validation-class/ Share on other sites More sharing options...
mikesta707 Posted January 9, 2010 Share Posted January 9, 2010 The point of OOP is to have different objects that do 1 job, and use them together. You probably want to create another class to access the database, and have the validate class interact with the database class to insert data (or alternatively, use the database class to validate the info by interacting with the validate class before inserting) Quote Link to comment https://forums.phpfreaks.com/topic/187889-access-database-inside-of-a-validation-class/#findComment-992015 Share on other sites More sharing options...
TheFilmGod Posted January 9, 2010 Author Share Posted January 9, 2010 The point of OOP is to have different objects that do 1 job, and use them together. You probably want to create another class to access the database, and have the validate class interact with the database class to insert data (or alternatively, use the database class to validate the info by interacting with the validate class before inserting) Thanks Mike. I have decided to use the validation class to do a basic validation on the input (check if it's not null, length, and valid characters), then I do a basic function check if the values match the database Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/187889-access-database-inside-of-a-validation-class/#findComment-992019 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.