Welcome Guest, Not a member yet? Register   Sign In
AR library : keep method order close to actual sql statement or not
#1

[eluser]xwero[/eluser]
i was wondering how other developers are using the AR library methods. You can do
Code:
$query = $this->db->select('field')->from('table')->where('field',$value)->get()
Or you can write it as
Code:
$this->db->select('field');
$query = $this->db->get_where('table',array('field'=>$value));

Which do you prefer and why?
#2

[eluser]gtech[/eluser]
I prefer the second option, I think its more through habit, as thats how I built my first AR queries and I haven't deviated from that.

In a few applications I have actually added another layer. I have a loggingsdb.php library which has the methods:- get,getwhere,insert,update,delete which then call the db functions. There are a few reasons I do this.

1. I can catch sql errors and return a meaningful error back to the calling function (a associative array gets returned containing error number and message)
2. I log all db calls and store them in the database
3. my delete method does not delete the data but marks rows for deletion
4. As I mark methods for deletion, in the insert functions I add a created date,version and a object-state flag. On the select functions I automatically add to the where clause the object-state's which are active.

*the get uses the db pointer so I can create flexible queries such as joins.
#3

[eluser]Michael Wales[/eluser]
I prefer the second option as well, since the first doesn't work on PHP4 servers.

Don't get into upgrade to 5 discussion with me - clients pay the bills, not my job to demand an upgrade, just my job to make it work.




Theme © iAndrew 2016 - Forum software by © MyBB