美文网首页
php 批量生成/删除表(测试用)

php 批量生成/删除表(测试用)

作者: 码农工号9527 | 来源:发表于2021-12-13 19:31 被阅读0次

生成:

<?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);
}

?>

相关文章

网友评论

      本文标题:php 批量生成/删除表(测试用)

      本文链接:https://www.haomeiwen.com/subject/wwfsfrtx.html