I've been reading docs regarding these 2 functions, but I still can't quite get the difference between these two.
I get it that get_where
selects data from DB, but when should we use where()
function and not get_where()
?
There are tons of other ways to get data using CodeIgniter’s ActiveRecord implementation, but you also have full SQL queries if you need them: Example:
$query = $this->db->get_where('people', array('id' => 449587));
Ultimately, get_where()
is the naive case, and certainly the most commonly-used in my code anyway — I can’t think of an another framework in any other language that enables you to be this productive with data with a single line of code.
get_where([$table = ''[, $where = NULL[, $limit = NULL[, $offset = NULL]]]])
Parameters:
This function is working as get()
but with also allows the WHERE
to be added directly.
Identical to the
$this->db->get();
except that it permits you to add awhere
clause in the second parameter, instead of using thedb->where()
function.
This function enables you to set WHERE clauses in your query.
You can also add where clauses, sort conditions and so forth:
$this->db->select('first_name', 'last_name');
$this->db->from('people');
$this->db->where('id', 449587);
$this->db->order_by('last_name, first_name');
$query = $this->db->get();
It’s possible to chain all these conditions together on a single line, but I prefer putting them on separate lines for readability.
In simple word, get_where
is a luxury to use but where()
gives you more flexibility to use.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With