database interaction in codeigniter

CodeIgniter Database Interaction

  1. Load the Database Library: Load the database library using the following code: php $this->load->database();

  2. Run Queries: You can run queries using the database object. For example: php $query = $this->db->query('SELECT * FROM my_table');

  3. Using Query Builder: CodeIgniter provides a query builder class to help you create and execute queries. For example: php $this->db->select('title, content, date'); $this->db->from('my_table'); $this->db->where('id', $id); $query = $this->db->get();

  4. Insert Data: Use the following code to insert data into a table: ```php $data = array( 'title' => 'My title', 'content' => 'My content', 'date' => 'My date' );

$this->db->insert('my_table', $data); ```

  1. Update Data: Update data using the following code: ```php $data = array( 'title' => $title, 'content' => $content, 'date' => $date );

$this->db->where('id', $id); $this->db->update('my_table', $data); ```

  1. Delete Data: Delete data using the following code: php $this->db->where('id', $id); $this->db->delete('my_table');