deleteById (method)

Last updated: Tue, Oct 31, 2023 11:31 am
Return to Knowledgebase


Delete a record from a database table based on given id




# Parameter Data Type Required Description
1 $table string Yes Name of database table to delete the record from
2 $id integer Yes ID of record to be deleted


$db->deleteById("permissions", 3);

Further Documentation:

1. Delete a record from a specified database table based on the provided id.
2. Constructs and executes an SQL DELETE statement using the provided table name and the id value.

// Example: Deleting a record from the 'users' table where the 'id' is 5

$result = $db->deleteById('users', 5);
if($result) {
echo "Deletion successful";
} else {
echo "Deletion failed or no matching record found";