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:
-#
$table
is the name of the table,
-#
$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,
-#
$serveur
,
-#
$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();
}