sql_drop_table

The sql_drop_table() function deletes an SQL table from the database. It returns true if successful, and false if not.

It accepts 4 parameters:

  1. $table is the name of the table,
  2. $exist is used to request verification of the table’s existence for the deletion (which translates into adding IF EXISTS to the SQL command). By default, '', it passes true to confirm the table is there before trying to delete it,
  3. $serveur,
  4. $option.

This sql_drop_table() function is used as shown below:

sql_drop_table('table');
sql_drop_table('table', true);

Example

Plugins often use this function for complete removal (data included) of a plugin when so requested by the administrator, as shown in this example from the "Géographie" plugin:

function geographie_vider_tables($nom_meta_base_version) {
	sql_drop_table("spip_geo_pays");
	sql_drop_table("spip_geo_regions");
	sql_drop_table("spip_geo_departements");
	sql_drop_table("spip_geo_communes");
	effacer_meta($nom_meta_base_version);
	ecrire_metas();
}

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

Translations : English, français