3

Hi I'm new to OOP with PHP. I'm wondering how OO comes into play when selecting data from a table. i.e. i have a users table and a user profile page. So I have a User class. Do I select the user data from the table then create a new object of class User and define the properties?

Thanks for anyone that can clear this up for me!

Regards,

Jonesy

3 Answers 3

4

Use ORM, like Doctrine or Propel.

See also Stackoverflow question "Good PHP ORM library"

Sign up to request clarification or add additional context in comments.

1 Comment

Hi thanks for the reply, I've looked up Doctrine which looks good. Do I have to go through all the steps to create models, etc with YAML. I already have my tables
2

That's it, you can create a UserManager class, that selects user data and create User object(s) (depending on you WHERE clause) with it. This class could have the following methods : selectUserById(), selectUsersByAge(), etc...

Comments

1

You can create a class to build MYSQL queries that can give you data from your DB, for example, you might have a method that give you a user by passing a parameter to that method, or you can have another method that give you the number of users in your table for example.

you can build your class in the way you need it.

After define a new instance of your class in your page you can use it to return data from your DB using the methods you defined them in your class and use it in your page as you want.

I hope this can help you.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.