我需要在尝试提交之前清理多个数据库中的几个表
$db_server = include('root.php');
if (!$db_server) die("Unable to connect to MySQL: " . mysql_error());
$sqla = "TRUNCATE TABLE `info`.`2012_august`";
$sqlb = "TRUNCATE TABLE `stu`.`2012_august`";
$sqlc = "TRUNCATE TABLE `stu`.`2012`";
if (@mysql_query($sqla))
{
echo ("success"."</br>");
}
else
{
echo ("un success".mysql_error()."</br>");
}
只有第一个表清除其数据。我该如何解决这个问题。
您的代码仅在执行$sqla
. 您需要执行其他操作,或将它们合并为一个用分号分隔的字符。
你有
$sqla = "TRUNCATE TABLE `info`.`2012_august`";
$sqlb = "TRUNCATE TABLE `stu`.`2012_august`";
$sqlc = "TRUNCATE TABLE `stu`.`2012`";
要存储的值。但是您只使用$sqla
来存储。这就是为什么其他值不存储的原因。You have to store them all by using comma
或by storing all the values into an array and call them at the time of store
.
$a = array("TRUNCATE TABLE `info`.`2012_august`", // create an array of queries
"TRUNCATE TABLE `stu`.`2012_august`",
"TRUNCATE TABLE `stu`.`2012`");
foreach ($a as $value) { // iterate through array
if (@mysql_query($value))
{
echo ("success"."</br>");
} else {
echo ("un success".mysql_error()."</br>");
}
}