From MODx Wiki
Jump to: navigation, search
API Quick reference
Function name: delete
Modx versions: >.9.1
Input parameters: (string $from [, string $where [, string $fields]])
Return if successful: true
Return type: bool
Return on failure: false
Object parents: DocumentParser->DBAPI
bool delete(string $from [, string $where [, string $fields]])

This function attempts to delete from the mysql table with the given paramaters. If no $where is given, this function will delete all the rows in the table $from. $where is the full string of a mysql where clause (eg: $where = "id=4 AND status='active'"). $fields denotes the specific fields to be deleted, leave blank to delete the whole row.

Function returns true on success, and false on failure.


//delete a user of id $id
global $modx, $table_prefix;
$id = $modx->db->escape($id);
$modx->db->delete($table_prefix.".modx_web_users", "id = $id");

Related functions

update, insert, select, query, getAffectedRows.

Function source

File: manager/includes/extenders/dbapi.mysql.class.inc.php
Line: 155
function delete($from,$where='',$fields='') {
   if (!$from)
      return false;
   else {
      $table = $from;
      $where = ($where != "") ? "WHERE $where" : "";
      return $this->query("DELETE $fields FROM $table $where");


As with all mysql calls, care must be taken to sanitize the variables passed. One should use $s = $modx->db->escape($s) before passing to any of these functions.

Personal tools