How to delete a row in database using codeigniter?

Member

by mac , in category: PHP Frameworks , 3 months ago

How to delete a row in database using codeigniter?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by darrion.kuhn , 3 months ago

@mac 

To delete a row in a database using CodeIgniter, you can use the following steps:

  1. Load the database library in your controller where you want to delete the row. You can do this by adding the following line in the constructor of your controller:


$this->load->database();

  1. Create a function in your controller that will delete the row. For example, to delete a row from a table named 'users' with an id of 1, you can use the following code:


public function delete_row() { $this->db->where('id', 1); $this->db->delete('users'); }

  1. Call the function in your controller using a route or a button click in your view.


That's it! This code will delete the row with the id of 1 from the 'users' table in your database. Make sure to replace 'users' with the actual table name and 'id' with the column name you want to use for deletion.