views:

84

answers:

3

Currently I am working with a commercial project with PHP. I think this question not really apply to PHP for all programming language, just want to discuss how your guys solve it.

I work in MVC framework (CodeIgniter).

all the database transaction code in model class.

Previously, I seperate different search criteria with different function name. Just an example

function get_student_detail_by_ID($id){}
function get_student_detail_by_name($name){}

as you can see the function actually can merge to one, just add a parameter for it. But something you are rushing with project, you won't look back previously got what similar function just make some changes can meet the goal. In this case, we found that there is a lot function there and hard to maintenance.

Recently, we try to group the entity to one ultimate search something like this

function get_ResList($is_row_count=FALSE, $record_start=0, $arr_search_criteria='', $paging_limit=20, $orderby='name', $sortdir='ASC')

we try to make this function to fit all the searching criteria. However, our system getting bigger and bigger, the search criteria not more 1-2 tables. It require join with other table with different purpose. What we had done is using IF ELSE,

if(bla bla bla)
{
   $sql_join = JOIN_SOME_TABLE;
   $sql_where = CONDITION;    
}

at the end, we found that very hard to maintance the function. it is very hard to debug as well.

I would like to ask your opinion, what is the commercial solution they solve this kind of issue, how to define a function and how to revise it. I think this is link project management skill. Hope you willing to share with us.

Thanks.

A: 

Congratulations, you have invented an ORM :)

There are plenty of commercial ORM solutions but, in my opinion, all they no better than yours. And I'd go for good ol' SQL.

Col. Shrapnel
what do you means by ol' good SQL is it old?
Shiro
+2  A: 

If you're using codeigniter, just use:

http://www.overzealous.com/dmz/

I don't know what I even used to do without it.

Matthew
wow.. that is new thing for me, thanks for the recommendation! bravo. I need more skill to do the commercial practice.
Shiro
A: 

After I did some research on ORM vs Active Record. For my situation I didn't find a lot of help by switching to ORM will help me better.

I found out that ORM is not do very in READ data. But good in Create, Update, and Delete.

My current solution is every model recompile the my own OR_WHERE() / AND_WHERE(), before pass to the $this->db->query(). It is more easy to maintain and customize.

Shiro