Delete records, emptyTable in codeigniter 4 - deesoft service

Delete records, emptyTable in codeigniter 4

Deepak Tailor Image
Deepak Tailor - Nov 28 2020
Delete records, emptyTable in codeigniter 4

In order to delete the data, the codeigniter function has given the delete function in the query builder. To delete any row from the table, we use the delete function. You can delete it directly and also delete it with condition.

public function delete_record()
{
	// $this->seller == database connect

	$query = $this->seller->table('users')
			->delete(['id'=>29]);
	if($query == true){
		echo "delete record";
	}
	else{
		echo "fail";
	}
}
Delete records with where condition
public function delete_record()
{
	$query = $this->seller->table('users')
			->where('id',29)
			->delete();
	if($query == true){
		echo "delete record";
	}
	else{
		echo "fail";
	}
}

public function delete_record()
{
	$args = [
		'id'	=>	44,
		'age'	=>	20,
		'salary>'	=>	2000
	];
	$query = $this->seller->table('users')
			->where($args)
			->delete();
	if($query == true){
		echo "delete record";
	}
	else{
		echo "fail";
	}
}

If a table has to be emptied in the database, then we use emptyTable or truncate function.

public function empty_table()
{
	$query = $this->seller->table('order')->emptyTable('order');
	if($query == true){
		echo "empty table";
	}
	else{
		echo "fail";
	}
}

public function empty_table()
{
	$query = $this->seller->table('users')->truncate();
	if($query == true){
		echo "truncate";
	}
	else{
		echo "fail";
	}
}
Deepak Tailor Image
Deepak Tailor

My name is Deepak tailor as a fullstack developer. I have been in the IT industry (PHP, Nodejs, flutter) for the last 5 years. For professional and customize web development & app development, you can send inquiry on our email.
----
You can contact him at deepaktailor10@yahoo.in