Member Avatar for arcticM

Hello, I learned Java few years back, and later learned PHP and built a website/application using php.
my website had a database and 98% of the code was not in OO (the other 2% I copy pasted fromt he internet)..
when I needed to display some data I made a query in my db and echo'ed it..
I had no use in using OO php while I was programming my website and now I'm having trouble making the connection between using PHP and OO..
why would I need to use OO? from java I know what OO means, but I never had the chance to apply it in something real (unlike some little homework code). if objects are used to store data..wouldn't it be better to use a DB for that?
let's say I want to save and use 2 persons' data, as I see it I either create a tblPerson in my db and enter 2 records, or I create a class called Person and then create 2 instances of that class, but the moment I stop running my code the instances disappear..so my question is where does OO fits in when creating real (not homework crap), big websites with a DB?

Recommended Answers

All 3 Replies

Member Avatar for diafol

I'm an OOP noob too. I don't think you should be looking at OOP to 'store data', it's more of a way of getting things done. For small projects I don't bother, however, for larger projects it's often invaluable when it comes to extending basic use or trying to avoid code duplication. One trait I'm trying to grow out of is creating classes and filling them with procedural code!

data objects, are not stored data like a database, they are the data from the data base stored in objects.

This may help Click Here

OO comes in when you want to create reusable, extensible blocks of code. There can be a connection between the database and objects, for example if you use an ORM. An object mapping directly to a table. The database functions will be hidden by the classes you use. One simple class will map to all your tables, you can use class properties to access column data. And although in theory you are right, that when the script is done, your object is lost, there are ways to serialize them into a session, and get them back out again.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.