Page 1 of 1

OOP PHP 5 with mySQL database

Posted: Mon Mar 12, 2007 1:10 pm
by duncanwilkie
OK - What I'm looking for is some advice on OOP in PHP5 with my already created and working mySQL database.

I'm wanting to create a property website, but a much more dynamic and useful website, than a simple list of houses and flats available.
Including:
  • Permissions Lists for Managers, Agents, Tennants (later with links to contractors available for fixing electric etc) even later on contractors (rates, why join? current jobs available etc);
    Different entrances according to Permissions list, including Info on current available properties;
    Financial data, total revenue, total opportunity cost, total costs, etc...
But before I get carried away, I need to point out that I am fairly new to PHP, mySQL and very new to OOP. I have read some books, tutorials, articles, and have created some simple PHP and xhtml. Apache & mySQL are setup and are working with PHP fine. I've created a property specific PHP document with functions, query the database, and return results in a table, with while, if and for statements. I have looked at OOP and understand it as being about creating a blueprint (called "class") of Objects in the same way we think about Objects in the real world.

So what I want a further understanding of is how I go about creating Objects or classes for a property website, the basic functions I have created have only done with querying the database, and outputting the data into a table with a form that asks if you want all properties or prop001 ... 3.

The Real Question
Is an individual 'Property' (ie. a house) an Object, or is the Table the Object in which the data is displayed?
Can I get some help on starting the basic structure of this project? OOP Design? Planning?
Should I using a library class php file and how do I access this within my project and on other pages?

Any help much appreciated, I'm learning PHP, with the goal of becoming a develop using PHP and other languages.
Will post code when I have some feedback on where to start, ie. property class or table class or both?

Posted: Mon Mar 12, 2007 1:19 pm
by feyd
In a fully object oriented environment you will have lots and lots and lots of objects.

For example a single permission would be an object, the manager of a group of permissions is another object, the user is an object (which can easily contain many more objects) etc etc.

So yes, a property is an object. Often so is the table that displays a list of properties.

Instead of jumping headlong into fully object oriented, I would suggest starting small and getting a feel for it all. Later, refactor the class(es) you've created into their own objects. In the end you will build your own library of classes and functions. You may or may not use other libraries, that is your choice. Until you are completely familiar with everything, I would suggest using as many existing libraries as you can to minimize the hill you're building for yourself to climb. ;)

Posted: Mon Mar 12, 2007 5:30 pm
by duncanwilkie
Thanks, at this feeling it would be both.

I've started to get more understanding of OOP; and using the functions. I'll have a go at something and hopefully I'll have something post worthy soon.

Posted: Mon Mar 12, 2007 5:38 pm
by RobertGonzalez
There is a lot more to OOP than using some PHP and some MySQL. It is a programming logic. It is extremely useful, very powerful and can completely bury you in crap if not done right. I agree with feyd. Start out small, keep hammering out procedural code, play a little with some OOP on smaller applications, then grow into it. And if you are going to go into PHP5 OOP, make sure to stay PHP5 OOP, as PHP4 OOP handling is really not on par with that of PHP5.

Posted: Mon Mar 12, 2007 6:50 pm
by duncanwilkie
All good advice. I do have a good understanding of condition statements and loops, from Excel, and some formal training, and self-taught.

I need to create more Functions, and understand how to pass variables between different functions and in the same classes. I'm looking at PHP5 OOP to make sure that I learn all the fundamentals of the programming design of OOP; but want to create real dynamic sites.

And I understand the principals of OOP, but its that thing of putting them into practice, again with keep variable values, in and out of loops, functions and classes. I also want to connect to db, and develop something dynamic.

Get Functions first then Class etc.

Posted: Mon Mar 12, 2007 6:57 pm
by RobertGonzalez
All of what you are talking about can just as easily be accomplished in procedural style. That is why I am saying start there. When you look at things like modularization, optimization, granularity, reusability, extensibility... then you are getting into the topics of how OOP improves your code. I am not saying that you are not talking about those things, but from what you have posted so far, it appears as though you may be looking to put procedural code into classes for the sake of calling it OOP. Which does have its benefits, but might not be exactly what was expected.

Posted: Mon Mar 12, 2007 7:09 pm
by duncanwilkie
Well I understand OOP has a way of building a blueprint of the object that will contain values and functions.

But I agree that at the moment, the trouble I'm having is moving my head away from procedural to OOP, and I'm glad you noted that, as its important to remember that.

And my theory or methodology is that I can create dynamic content by referring to data about Properties, and then call functions to either update records, or display a set of results like available Properties, and then display information about separate Properties. Gas yes/no; electric yes/no; and rent generated etc...

Thats my I want to use classes and methods, and use reuseable classes from my own libraries for display result tables, or displaying a page for an individual property, include css class calls.