Jump to content

Recommended Posts

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!

 

 

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)

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!

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.