tags:

views:

107

answers:

3
+2  Q: 

OOP PHP and MySQL

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  A: 

Use ORM, like Doctrine or Propel.

See also Stackoverflow question "Good PHP ORM library"

vartec
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
iamjonesy
+1  A: 

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

greg0ire
+1  A: 

Hi

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.

SzamDev