Is a universal get() method like the one below a good idea
function universal_get( $select=NULL, $from=NULL, $where=NULL, $group=NULL, $having=NULL, $order=NULL, $limit=NULL )
{
// condition checks
if ( is_string( $select ) OR is_array ( $select )) { $this->db->select( $select ); }
if ( is_string( $from ) ) { $this->db->from( $from ); }
if ( is_array( $where ) ) { $this->db->where( $where ); }
if ( is_string( $group ) OR is_array( $group ) ) { $this->db->group_by( $group ); }
if ( is_array( $having ) ) { $this->db->having( $having ); }
if ( is_array( $order ) ) { $this->db->order_by( $order ); }
if ( is_string( $limit ) OR is_int( $limit ) ) { $this-开发者_JAVA百科>db->limit( $limit ); }
$result = $this->db->get( $from );
if ( $result->num_rows() > 0 ) { return $result->result(); }
else { return FALSE; }
}
or would an ORM like PHP-ActiveRecord be a better option?
Thanks
Strait forward: No
If you are a programmer then write good code. When I started with CI I was making functions like these all over the place and it very confusing. CI is a framework so basically you are building a framework off of a framework.
Another thing to keep in mind is, you need to always know what going on in the code. Having functions that do too much cause bugs which are hard to trace and restrict usability to specific applications. For instance what if you want to use a join? All properly designed databases will use a join eventually.
I dont think thats a good idea. CI's Active Record takes care of things you dont want to deal with... Add slashes, chaining where and a few others.. just check out their class.
http://codeigniter.com/user_guide/database/active_record.html
精彩评论