DB::delete (method)

Last updated: Tue, Oct 31, 2023 1:43 pm
Return to Knowledgebase

Purpose

Delete records from a specified database table based on condition

Location

users/classes/DB.php

See Also:

Parameters

# Parameter Data Type Required Description
1 $table string Yes Name of database table to delete records from.
2 $where array Yes Associative array representing the condition(s) to identify the records to be deleted.

Example

$db->delete("permissions", ["name","=","SuperAdmin"]);

Further Documentation:

Used to delete records from a specified database table based on the provided condition array (where clause).

// Condition Array:
// [ Column name, Type of comparison, Values]
// Deleting records from the 'users' table where the 'id' is 5
$result = $db->delete('users', ["id", "=", 5]);

// more examples or condition arrays
["username", "LIKE", "a{3bc1fe685386cc4c3ab89a3f76566d8931e181ad17f08aed9ad73b30bf28114d}"]
["custom5", "IS NULL"]
["logins", "BETWEEN", 10, 30]
["permissions", "IN", [1,2]]

Allowed operators:
=, <, >, <=, >=, <>, !=, LIKE, NOT LIKE, ALIKE, NOT ALIKE, REGEXP, NOT REGEXP
IS NULL, IS NOT NULL
BETWEEN, NOT BETWEEN
IN, NOT IN