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:

  1. sql_drop_table('table');
  2. sql_drop_table('table', true);



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:

  1. function geographie_vider_tables($nom_meta_base_version) {
  2. sql_drop_table("spip_geo_pays");
  3. sql_drop_table("spip_geo_regions");
  4. sql_drop_table("spip_geo_departements");
  5. sql_drop_table("spip_geo_communes");
  6. effacer_meta($nom_meta_base_version);
  7. ecrire_metas();
  8. }


Author Mark Baber Published : Updated : 02/06/10

Translations : English, français