生成:
<?php
$conn = mysql_connect(host,user,pwd) or die ("wrong!");
$sel=mysql_select_db("test", $conn);
for ($i = 0; $i < 10; $i++){
$tb_name = 'tb_for_test_'.$i;
$sql = "CREATE TABLE IF NOT EXISTS `"
.$tb_name
."` ( `id` int(10) NOT NULL DEFAULT '0', `val` bigint NOT NULL DEFAULT '0' ) ENGINE=InnoDB;";
$que = mysql_query($sql,$conn);
var_dump($tb_name);
}
?>
删除:
<?php
$conn = mysql_connect(host,user,pwd) or die ("wrong!");
$db_name = 'test';
$sel=mysql_select_db($db_name, $conn);
$sql = "show tables;";
$que = mysql_query($sql,$conn);
while($row = mysql_fetch_assoc($que))
{
var_dump($row['Tables_in_'.$db_name]);
mysql_query("drop table ".$row['Tables_in_'.$db_name],$conn);
}
?>
网友评论