Jump to content
Stef's Coding Community
Sign in to follow this  
pb1uk

Object Oriented PHP and MySQL

Recommended Posts

Hello all,

 

I would say by now i'm fairly familiar with PHP and have made a few database driven sites using PHP and MySQL. However as i'm sure some will know it becomes increasingly frustrating have sql and php code dotted all over the place. With my last site it became a bit of a pain. I'm about to start a new project so thought it was about time i learnt to do object oriented php. I've done a couple of starter tutorials (inc stefans on here - very good starting point by the way) and want to take it a bit further.

 

I basically want to create classes for the tables of my databases and have all the queries i am going to use in there so they're all in one place. Does anyone know of any resources or good tutorials for this kind of thing? I've found a couple, but i'm i'm looking for something specifically related to oo php and mysql.

 

Thanks in advance

 

pb1uk

Edited by pb1uk

Share this post


Link to post
Share on other sites

I don't really know good tutorials. But I could suggest one thing, which would help you keep your code organised.

 

MVC - Model -> View -> Controller (http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller)

 

It's a nice architecture, and a way of sorting your PHP files so you separate the display from processing.

 

Joomla and other popular CMS's use this approach.

 

 

Personally, I think if you keep all your SQL in one class, it's kinda counter-intuitive to the whole Object Oriented approach. An SQL statement for a particular object should be generated within that object, not coming from another class. But that's not really a restriction, there's nothing stopping you from doing it this way :rolleyes:

 

My 2cents.

Share this post


Link to post
Share on other sites

Thanks i'll read up on that.

 

I want to have seperate classes for the different db tables e.g. user class, post class etc, so ideally i want to have my sql for each table grouped together but kept seperate from other tables, if that makes sense.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...