Topic: OOP with database

Hallo Stefan,

Thanks for great tutorial. Finally someone who doesn’t bore you with only theory!

I’m a student and learning oop with php.

How we were taught is to begin with making the structure of you system and then make a table structure and so on….

I’ve made the a table structure and want to translate it into oop php and don’t know if I’m doing it right?

Here is an example:
http://www.island-data.com/downloads/papers/graphics/Normalization-4.gif
Figure 1

How do you translate this into oop???

Something like this:

class customer{

    //vars
    $first_name;
    $last_name;
    $company;
    $city;
    $state;
    $zip_code;
    $phone;
    $fax;
    $email

    //functions
    function get_first_name(){
        return $this->first_name;
}

}

And how do you combine everything together???

Can you please give me an example??

Thanks in advance

Re: OOP with database

The diagram you show is basically how the database is put together, showing the relationship between tables. You'll want to figure out roughly what you want to do in your code, and then work from there. The database diagram doesn't really tell me what you intend your application to do, so I really can't help here.

Re: OOP with database

I want to be able to register users manually, show which products they bought, show a summery etc.
Do I have to make classes as table structures or is there another way?

example:

Make classes of these database tabels and then create objects and work with objects.

Thanks

Re: OOP with database

Hi,

There are many ways to approach this. The manual way would be to create a series of data objects (objects who's job it is to interact with the database) and in those objects, would contain your php database code.

You would then create another bunch of 'controller' objects that would use your database objects to interact with the database objects. Hard to understand in one sentence I know ...

This come down to MVC architecture. We cover that in our php shopping cart tutorial and in our advanced php lessons that are coming out now.

The links:

http://www.killerphp.com/tutorials/shop … -tutorial/

http://www.killerphp.com/articles/getti … ts-part-1/

The other way is to use something like the zend framework where they have set up a structure/framework where they worked this out.

Stefan

Re: OOP with database

Hi Stefan,

Thanks for the tips. I'm busy with an example and I'm gona post it when I finished it.

It might be a good idea to buy the tutorials to get good inside.

Leon