Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2008

    Unanswered: Wich the best way to control the logic of a web application?


    Now I'am with some doubts on how to control the logic of a web application?

    So... the web application uses PHP, object oriented and PostgresSQL Database. I have developed some procedures and functions in the database but I don't know if it is correct to mix logic in the database and PHP.

    What do you think aboout this? Should I mix logic in Database and PHP or should I control the logic only in the PHP?

    Best Regards,
    Wich the best way to control the logic of a web application?

  2. #2
    Join Date
    Jan 2005
    Sorry for the late replay,I logg in today.
    Functions that run at the database run quicker than with php (running 'inside' the database), but when you change the database you have to write again the functions.
    I thing 'business' logic must be all together at php and to use more database specific functions at database (to insert a value at insertion etc).
    You may read about mvc (example)
    Last edited by dimis2500; 09-02-09 at 06:40.

  3. #3
    Join Date
    Jun 2007
    I go completely the other way and try and put as much business logic in the database procs as possible. Reasons are:
    • it's easy to encapsulate the logic into a single proc and then call that proc from lots of different places
    • it's easier to test the logic from the command line
    • the code is less complex - thinks lot's of separate pieces of SQL being called from within your PHP logic and the results all being tested etc etc as opposed to just calling a single proc.
    • it will be way faster

    I'd just look at your database and decide what all the "actions" are that need to be performed on your data and then make those actions your procs. That's not to say no logic at all should go in your PHP but if the logic concerns the data in your database then the logic should be in your database to.

  4. #4
    Join Date
    Jan 2005
    This is a good idea when your logic is database related.
    But what about not database related logic as connecting with web services,services from external sites or a session shopping card?.
    You will have 2 buisness logic layers ?
    The plus you write, you may have them when you will use a framework as Yii or your framework with simiral logic.
    For example you write a model function returning the data you want[edit]Maybe the model functions use database procs-this is not related with your php application logic.
    As I already said it is quicker the database related procedures to run inside databases ,another is that we can use them from separate programs (web app and desktop application for example).
    Last edited by dimis2500; 09-06-09 at 06:16.

Posting Permissions

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