Ver Mensaje Individual
  #1 (permalink)  
Antiguo 18/11/2011, 11:45
bernardo
 
Fecha de Ingreso: junio-2003
Mensajes: 940
Antigüedad: 20 años, 10 meses
Puntos: 8
Pregunta ¿Borrar todas las tablas que empiecen por temp_?

Buenas

¿Cómo puedo borrar todas las tablas de una base de datos que empiecen por temp_?

Es para borrar las tablas de un CMS que me las genera.

En un foro he visto el siguiente script, pero no me lo hace:


<?php




function clear_temp () {

// checks for tables that begin with variable $tmp_table_prefix then deletes them
global $conn, $config;

// set temp_table_prefix (adjust as necessary)
$tmp_table_prefix = $config['table_prefix']. 'temp_';

$sql = "SHOW TABLES LIKE '$tmp_table_prefix%'";
$recordSet = $conn->Execute($sql);

if (!$recordSet) echo($sql);

$num = $recordSet->RecordCount();

// create query string to delete all tables that begin with $tmp_table_prefix
$sqlD = "DROP TABLE IF EXISTS ";

for ($loop=0; $loop < $num;)
{
$loop++;
$sqlD .= $recordSet->fields[0];

if (($num - $loop) > 0) $sqlD .= ", ";
$recordSet->MoveNext();
}

//echo $sqlD;

// Nuke those tables
$recordSetD = $conn->Execute($sqlD);

if (!$recordSetD) echo($sqlD) .' -- none exist';

else echo '<br>Finished';

} //end function clear_temp ()


?>


Muchas Gracias