Codeigniter's `where` and `or_where`

In CodeIgniter, the where method on the database class is used to add a WHERE clause to your query. It can be used in several ways:

<?php

$this->db->where('name', $name);

// Produces: WHERE name = 'Joe'
<?php

$this->db->where('name', $name);
$this->db->where('title', $title);

// Produces: WHERE name = 'Joe' AND title = 'boss'

Watch a course Learn object oriented PHP

You can also use the or_where method in a similar way to add OR clauses to your query:

<?php

$this->db->or_where('name', $name);

// Produces: OR name = 'Joe'
<?php

$this->db->where('name', $name);
$this->db->or_where('title', $title);

// Produces: WHERE name = 'Joe' OR title = 'boss'

You can also pass an array to where and or_where:

<?php

$array = ['name' => $name, 'title' => $title];
$this->db->where($array);

// Produces: WHERE name = 'Joe' AND title = 'boss'

You can use the where method multiple times to build up a WHERE clause with multiple AND clauses. The or_where method can be used to add OR clauses to the WHERE clause.