OOP in php - MySql db - Objects

Discussion in 'PHP' started by alfgeorg, Apr 3, 2008.

  1. #1
    I'm trying to learn OOP with php and MySql.
    I have a table with lot of students (names, e-mail etc.)

    Do I make one object for each pupil or one large object with all the pupils in it?
    How to load data from the table and then make many objects at the same time?

    Can anyone give me som starting help here?
     
    alfgeorg, Apr 3, 2008 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    If you're looking for something that makes a database table into an object itself, then I think something like propel http://propel.phpdb.org/trac/ is what you're looking for. This is an ORM framework. With it you can access a database just like you would access a normal php class. Using your example, you would use something like:

    
    
    $student = new studentDB;
    $student->setId(1);
    
    $student->getName(); 
    
    
    PHP:
    to access a student's name, etc..

    If you're just trying to use an OOP method of accessing a database, then php has the built-in mysqli database class. http://www.php.net/mysqli
     
    jestep, Apr 3, 2008 IP