Results 1 to 2 of 2
  1. #1
    Join Date
    May 2008

    Unanswered: Organizing db code in php

    Hi all,

    I don't have a lot of experience with php and mysql. I am trying to avoid hard coding the table names and table attributes in every php page I use them in. in case the names are changed I won't have to update every page. I was wondering what is the best way to organize db code in a php application. Thanks


  2. #2
    Join Date
    Nov 2004
    out on a limb
    Provided Answers: 59
    why would you be changing your tbale names whilst in development.. sounds to me like you are coding before completing the design.... tut tut.

    I don't know of any way of gettign round that completely. one way you can do that is to go donw the object orientated design route.. place all SQL code inot the relevant classes. fiazling thast you are always going to have to revist the SQL.. if you have a decent editor it shoudl be able to find all references to that table/column/whatever in all scripts, failing that a tool like GREP is a good alternative

    of course there are trade offs.. you cannot use some of the more elegant features of SQL, and I think there is a fundamental logical conundrum between RDBMS & SQL and a fully formed OO design.. but nothing comes from a free lunch.

    investigate classes in PHP would be my advice. you can always buffer name changes in SQL tables & rownames accross the classes properties and methods. used sensibly classes & the OOD approach is a great boon, especially in PHP where its all to easy to 'knock up' some code which becomes a maintenance nightmare over the years. OOD is great but like any tool it has its limitations and issues, in my books its not the panacea that its more rabid proponents seem to rave about.
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts