PHP 清空 MysqL 指定数据表中的所有数据,在小编在网上闲逛时,这是某技术博客的一篇文章,说是文章,并没有文字,只有代码,经过测试可以使用,现在分享给大家。
共有三个文件,其实也可以合并写成一个。
1.conn.PHP:
<?PHP
$id=MysqL_connect("localhost","root","MysqL") or die('连接失败:' . MysqL_error());
if(MysqL_select_db("PHPjcdb",$id)) //说明:PHPjcdb 是数据库名称
echo "";
else
echo ('数据库选择失败:' . MysqL_error());
MysqL_query("set names gb2312"); //设置为简体中文
?>
$id=MysqL_connect("localhost","root","MysqL") or die('连接失败:' . MysqL_error());
if(MysqL_select_db("PHPjcdb",$id)) //说明:PHPjcdb 是数据库名称
echo "";
else
echo ('数据库选择失败:' . MysqL_error());
MysqL_query("set names gb2312"); //设置为简体中文
?>
2.index.PHP:
<?PHP
include("conn.PHP");
?>
<html>
<head>
<Meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>清空指定数据表中的所有数据</title>
<style type="text/css">
<!--
.STYLE2 {font-size: 13px}
.STYLE3 {font-size: 12px}
-->
</style>
</head>
<script language="javascript" type="text/javascript">
function deletes(){
if (window.confirm('确定要删除该记录??')==true){
return true;
}else{ return false;}
}
</script>
<body>
<form action="index.PHP" method="post" name="form1" id="form1">
<table width="614" height="90" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="20" height="53"> </td>
<td width="219"> </td>
<td width="355"> </td>
<td> </td>
</tr>
<tr>
<td height="26"> </td>
<td align="right"><select name="select">
<?PHP
$result = MysqL_list_tables ("db_database06");
$i = 0;
while ($i < MysqL_num_rows ($result)) {
$tb_names = MysqL_tablename ($result,$i);
?>
<option value="<?PHP echo $tb_names;?>"><?PHP echo $tb_names;?></option>
<?PHP $i++; }?>
</select> </td>
<td><input type="submit" name="Submit2" value="提交" /></td>
<td width="20"> </td>
</tr>
<tr>
<td height="5"> </td>
<td align="right"> </td>
<td> </td>
<td> </td>
</tr>
</table>
<table width="614" height="25" border="0" cellpadding="0" cellspacing="0" background="images/bg03.jpg">
<tr>
<td width="20"> </td>
<td width="569">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<?PHP
if($_POST['Submit2']=="提交"){
$select = $_POST['select'];
$query1=MysqL_query("select * from $select");
$query2=MysqL_query("select * from $select");
$myrow=MysqL_fetch_row($query2);?>
<tr>
<?PHP for($i=0;$i<count($myrow);$i++){?>
<td align="center">
<span class="STYLE2"> <?PHP echo MysqL_field_name($query2,$i);?></span></td>
<?PHP } ?>
</tr>
<?PHP while($myrow=MysqL_fetch_row($query1)){ ?>
<tr>
<?PHP for($i=0;$i<count($myrow);$i++){?>
<td align="center"><span class="STYLE3"> <?PHP echo $myrow[$i];?></span></td>
<?PHP } ?>
</tr>
<?PHP } } ?>
</table></td>
<td width="20"> </td>
</tr>
</table>
</form>
<form action="index_ok.PHP?lmbs=<?PHP echo $select;?>"
method="post" name="form2" id="form2" onSubmit="return deletes();">
<table width="614" height="28" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="center"><input type="submit" name="Submit" value="删除数据"></td>
</tr>
</table>
</form>
</body>
</html>
include("conn.PHP");
?>
<html>
<head>
<Meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>清空指定数据表中的所有数据</title>
<style type="text/css">
<!--
.STYLE2 {font-size: 13px}
.STYLE3 {font-size: 12px}
-->
</style>
</head>
<script language="javascript" type="text/javascript">
function deletes(){
if (window.confirm('确定要删除该记录??')==true){
return true;
}else{ return false;}
}
</script>
<body>
<form action="index.PHP" method="post" name="form1" id="form1">
<table width="614" height="90" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="20" height="53"> </td>
<td width="219"> </td>
<td width="355"> </td>
<td> </td>
</tr>
<tr>
<td height="26"> </td>
<td align="right"><select name="select">
<?PHP
$result = MysqL_list_tables ("db_database06");
$i = 0;
while ($i < MysqL_num_rows ($result)) {
$tb_names = MysqL_tablename ($result,$i);
?>
<option value="<?PHP echo $tb_names;?>"><?PHP echo $tb_names;?></option>
<?PHP $i++; }?>
</select> </td>
<td><input type="submit" name="Submit2" value="提交" /></td>
<td width="20"> </td>
</tr>
<tr>
<td height="5"> </td>
<td align="right"> </td>
<td> </td>
<td> </td>
</tr>
</table>
<table width="614" height="25" border="0" cellpadding="0" cellspacing="0" background="images/bg03.jpg">
<tr>
<td width="20"> </td>
<td width="569">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<?PHP
if($_POST['Submit2']=="提交"){
$select = $_POST['select'];
$query1=MysqL_query("select * from $select");
$query2=MysqL_query("select * from $select");
$myrow=MysqL_fetch_row($query2);?>
<tr>
<?PHP for($i=0;$i<count($myrow);$i++){?>
<td align="center">
<span class="STYLE2"> <?PHP echo MysqL_field_name($query2,$i);?></span></td>
<?PHP } ?>
</tr>
<?PHP while($myrow=MysqL_fetch_row($query1)){ ?>
<tr>
<?PHP for($i=0;$i<count($myrow);$i++){?>
<td align="center"><span class="STYLE3"> <?PHP echo $myrow[$i];?></span></td>
<?PHP } ?>
</tr>
<?PHP } } ?>
</table></td>
<td width="20"> </td>
</tr>
</table>
</form>
<form action="index_ok.PHP?lmbs=<?PHP echo $select;?>"
method="post" name="form2" id="form2" onSubmit="return deletes();">
<table width="614" height="28" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="center"><input type="submit" name="Submit" value="删除数据"></td>
</tr>
</table>
</form>
</body>
</html>
3.index_ok.PHP: