query builder codeigniter 4 code example

Example 1: how to print mysql query of codeigniter query builder

To display the query string:

print_r($this->db->last_query());    

To display the query result:

print_r($query);

Example 2: query builder codeigniter

$this->db->set('name', $name);
$this->db->set('title', $title);
$this->db->set('status', $status);
$this->db->insert('mytable');

Example 3: codeigniter 4 query builder select

$builder->select('title, content, date');
$query = $builder->get();

// Executes: SELECT title, content, date FROM mytable

Tags:

Sql Example