sql_delete

The sql_delete() function is used to delete records from an SQL table and returns the number of records that were all deleted.

It has 4 parameters:

  1. $table is the name of the SQL table,
  2. $where,
  3. $serveur,
  4. $option.

It is used as shown below:

sql_delete('table', 'id_table = ' . intval($id_table));

Example

Delete the link between all sections and a given keyword:

sql_delete("spip_mots_rubriques", "id_mot=$id_mot");

One of SPIP’s standard periodical tasks is to delete old articles that have been put in the dustbin (poubelle), as detailed below:

function optimiser_base_disparus($attente = 86400) {
	$mydate = date("YmdHis", time() - $attente);
	// ...
	sql_delete("spip_articles", "statut='poubelle' AND maj < $mydate");
}

Author Mark Baber Published : Updated : 12/03/23

Translations : English, français